I am getting an error with a program. Evidently I'm missing something about the syntax. The snippet of C++ code below is the smallest which produces the error.
#include <iostream>
using namespace std;
class Parent
{
public:
enum MyEnum {
Value1,
Value2,
Value3
};
MyEnum* set;
};
class Child: public Parent
{
public:
Child()
{
set = new MyEnum[5];
set[0]=MyEnum.Value1;//<--Something wrong here
set[1]=MyEnum.Value2;//<--Something wrong here
set[2]=MyEnum.Value3;//<--Something wrong here
set[3]=MyEnum.Value2;//<--Something wrong here
set[4]=MyEnum.Value1;//<--Something wrong here
}
void Write()
{
for(int i=0;i<5;i++)
{
cout<< "This is " << i << ": " << set[i];
}
}
};
int main() {
Child c;
c.Write();
return 0;
}
The error has something to do with the indicated syntax.
expected primary-expression before ‘.’ token
I have tried Parent.MyEnum.Value1, Parent::MyEnum.Value1, etc. nothing seems to be right. How should I be referring to the specific values in the parent class?