class CRA_Account {
int tax[4];
double refund[4];
int SIN;
public:
CRA_Account();
}
CRA_Account::CRA_Account() {
SIN = 0;
tax[4] = { 0 };
refund[4] = { 0 };
}当我在main中创建一个对象时,它会将SIN设置为0,但不会对数组执行相同的操作。有人能帮我解释一下原因吗?
发布于 2018-02-15 02:06:10
tax[4] = { 0 };在很多层面上都是错误的。初始化你的类的一种方法:
CRA_Account::CRA_Account():
tax{0,0,0,0},
refund{0,0,0,0},
SIN{0}{
}Online
试着看看std::array
https://stackoverflow.com/questions/48793373
复制相似问题