2
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?

6
  • Arrays are not assignable. Commented Feb 14, 2018 at 17:53
  • Use the initializer list to construct attributes. What you're doing here is an assignment and that doesn't work with arrays. Commented Feb 14, 2018 at 17:53
  • Here ideone.com/CQBvR8 the part starting with the colon before the constructor body is called a member initializer list Commented Feb 14, 2018 at 17:56
  • 1) use the initializer list. 2) there's std::fill. 3) why not a std::array? Commented Feb 14, 2018 at 18:05
  • @Caninonos That worked. Thanks! Commented Feb 14, 2018 at 18:06

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.