Reputation: 11088
The code bellow will give compile error on line enum en = A::en;
but it describes what I want to do (to make nested enum of A
to be nested enum of B
as well).
#include <iostream>
using namespace std;
struct A
{
enum a_en{X = 0, Y = 1};
};
struct B
{
enum b_en = A::a_en; //syntax error
};
int main()
{
cout << B::X << endl;
return 0;
}
So the question is how can I do such thing in c++?
Upvotes: 6
Views: 1464
Reputation: 18411
When the classes/structs are related this way, you should inherit them. Put the public enum in base class so that all derived (related) classes can access it.
MFC' CFile
class has enums defined, which CStdioFile
and other derived classes can use:
enum OpenFlags {
modeRead = (int) 0x00000,
modeWrite = (int) 0x00001,
... };
Upvotes: 0
Reputation: 92241
Put the enum in a base class that both A and B can inherit from.
Upvotes: 5