How do you import an enum into a different namespace in C++?

前端 未结 5 1750
心在旅途
心在旅途 2020-12-11 14:20

I have an enum in a namespace and I\'d like to use it as if it were in a different namespace. Intuitively, I figured I could use \'using\' or \'typedef\' to accomplish this,

5条回答
  •  旧巷少年郎
    2020-12-11 14:56

    While i like the approach of Mark B best, because it doesn't break existing code, you can also do the following:

    namespace foo {
     enum bar {
      A, B [..]
     };
    }
    
    namespace buzz {
     using foo::bar;
     using foo::A;
     using foo::B;
     [..]
    }
    

提交回复
热议问题