Question:
I’m trying to declare some data for an object such that, when necessary, other functions can use the object not only to perform member functions but also serve as a ‘data container’.
For example, I’m declaring a Date object that, among other things, contains an array of all the month ends. So in the class declaration I’d like to do this:
class Date {public: Date(); ~Date(){}; int monthEnds[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};};
And from then on be able to rely the Date object to say:
February = Date::monthEnds[2];
I am going insane trying to find a good referrence for declaring array data within a class.
Answer:
You cannot initialize data memebers inside the class body. You need to perform the initialization inside the constructor.