I’m working on a C++ project. I’m teaching myself C++ after using Java. Code:
#include <iostream>
#include <string>
using namespace std;
class dayType
{
private:
string day;
string week[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
public:
dayType()
{
day = "Monday";
dayID = 0;
}
};
There are more public functions, but I left those out because they aren’t important here. There is a compile time error on the array. It says it is “Unable to resolve identifier: week”, “unexpected token: {“, and “unexpected token:}”. Can someone explain why this is happening? If I declare it as “string week[7];” and then define the actual values in the functions, it works fine, but that’s a pain.
The C++ feature you are looking for is “static class members”. Here is the syntax: