每当我运行构造函数钱的注释部分程序崩溃。 当我编译它时,它也不会抛出任何错误。 有人能告诉我发生了什么事吗?每当我运行注释代码时程序崩溃
另外我想在这里实现自动售货机的问题。 我已经删除了一些正常工作的代码部分。
#include <iostream>
using namespace std;
class money
{
public :
int *max;
int *accepted_values = new int[10];
bool present;
int *deposited;
int i;
money()
{
}
money(int *a, int how_many)
{
//*max = how_many;
// for (i=0; i<how_many; i++)
// {
// accepted_values[i] = a[i];
// }
//*deposited = 0;
present = false;
}
};
class Vending_machine
{
public :
money *coins = new money(accepted_coins, 5);
//money *coins = new money();
int *amount_deposited = new int;
Vending_machine()
{
cout<<"Cool";
}
~Vending_machine()
{
delete amount_deposited;
}
};
int main()
{
Vending_machine a;
}
['using namespace std ;' is bad practice](https://stackoverflow.com/q/1452721/2176813),请勿使用它。 – tambre
无法用GCC 6.3重现。请告诉我们您的编译器和编译器版本。也就是说,如果你的编译器遇到一个ICE,我们可以做的事情就不多了,除了推荐你更新你的编译器,或者通过适当的渠道将它作为一个错误进行存档。 – tambre
显示它如何崩溃。发布编译器错误消息会很有帮助。 – ks1322