qq_31549215 2015-09-24 02:18 采纳率: 0%
浏览 2464

0xC0000005: 读取位置 0xCDCDCDCD 时发生访问冲突。

void shop::Pay(){
if (basket == NULL)
return;
float sum = 0.0;
float sum_tax = 0.0;
for (i = 0; &basket[i] != NULL; i++)
{
basket[i].GetPrice();
sum_tax += basket[i].tax;
sum += basket[i].at_price;
}
cout << sum_tax << endl;
cout << "Total:" << sum << endl;
return;
}

void goods::GetPrice(){
if (this == NULL)
return;
float rate = 0.1f;
if (isExempt)
rate -= 0.1f;
if (isImported)
rate += 0.05f;
tax = count*price*rate;
at_price = count*price+tax;
cout << count << " " << name << ":" << at_price << endl;
}

在GetPrice执行第三次时报错,这是栈溢出吗?应该怎么改?虚心求教!

  • 写回答

2条回答

  • 91program 博客专家认证 2015-09-24 03:23
    关注

    在GetPrice执行第三次时报错,具体 是调用语句处,还是执行GetPrice内的代码?
    建议你调试一下,单步看看具体是哪一步出错了,然后重点分析这一步的代码其中用的变量等。
    例如:basket[i] 在第三次执行时,其值是不是为空了???

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器