[Solved] c++ array of type class [closed]


The first you have correctly identified is caused by access to a private member. The fix? A public member function which returns the menu:

string getMenu();

The second is an invalid attempt to treat ‘mimmos’ as an array when infact it is a single instance. Since the comment above it indicates it is an attempt to get information about the third shift. You have two choices: change the “getShifts” function to take an index parameter:

string getShift(size_t n) {
    return Shifts[n];
}

and then you would obtain information about the 3rd shift by writing:

cout << "Shift info: " << mimmos.getShift(2) << std::endl;

Or change getShifts() to return an array pointer:

string* getShifts();

then you would write:

cout << "Shift info: " << mimmos.getShifts()[2] << std::endl;

solved c++ array of type class [closed]