1

I'm trying to use existing 3rd party enum type of the form:

enum EnumType 
{
    ONE,
    TWO,
    THREE
}  

in my project with two usages:

  1. in some files I would like to import this enum and put it into an existing namespace (e.g "namespace myproject").
  2. in file API.h I would like to import this enum just to declare method with return type of this enum (in cpp file I would just make cast from myproject::EnumType to EnumType)

The reason why I want to do this is that I don't want to put the definition of the enum in the API header's namespace.

I have problem with the first point, how can I do it?

2
  • Would it make sense to put the #include API.h in the namespace? Commented May 17, 2016 at 13:05
  • Why do you not want to put the definition in the API header's namespace? Commented May 17, 2016 at 13:09

1 Answer 1

1

Would a using EnumType not suffice for your use; a using-declaration...

namespace my_project {
  using ::EnumType;
  //...
}

If you still want to "hide" the EnumType from being visible in your public API, then you can create an enum of your own with the same values and convert between the two in your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.