Having trouble initiating an array in a structure

2019-07-12 14:15发布

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 };
 }

When I create a object in main it'll set the SIN to 0 but won't do the same to the arrays. Can someone help why?

标签: c++ class
1条回答
\"骚年 ilove
2楼-- · 2019-07-12 14:44

tax[4] = { 0 }; is wrong at many levels.. One way to initlizie your class:

CRA_Account::CRA_Account():
   tax{0,0,0,0},
   refund{0,0,0,0},
   SIN{0}{
}

Online

Try to have a look at std::array

查看更多
登录 后发表回答