how to typdef an enum of one namespace inside another and use ist c++ -
possible duplicate:
how import enum different namespace in c++?
how can following enum namespace problem been solved?
namespace { typedef enum abar { a, b }; void foo( abar xx ) {} } namespace b { typedef enum a::abar bbar; void foo( bbar xx ) { a::foo( xx ); } } int main() { b::foo( b::a ); // 'a' : not member of 'b' // 'a' : undeclared identifier }
while typedef type, don't import symbols defined in namespace. while can write:
int main() { b::bbar enumvariable=a::a; }
you cannot access b::a
symbol not exist.
a partial walkaround and, in opinion, way make code more clean, although bit more longer write, pack every enum own struct, e.g.:
struct abar { enum type {a, b}; }; typedef abar bbar; int main() { abar::type var=abar::a; bbar::type var2=bbar::a; }
you able to, if still need it, pack abar namespace , typedef in namespace too.
Comments
Post a Comment