c++ - Enumeration access in different class -
i have enumeraion in class , class b have class instance member. how can access class enumeraion in class b using instance
class a{ enum ab{ 1, b 2 }; }
in class b need enumeraion
#include <iostream> using namespace std; class a{ public: enum ab{ a= 1, b= 2 }; }; class b{ public: void test() { enum a::ab x=a::a; cout << "test a::a = " << x << endl; x=a::b; cout << "test a::b = " << x << endl; } }; int main() { cout << "a::a = " << a::a << endl; cout << "a::b = " << a::b << endl; class b b; b.test(); }
the enumerated names a,b reside in class namespace so, can access them using a::
prefix a::a
.
Comments
Post a Comment