How to use enum from a different namespace?

T

toton

I have an enum in a namespace like,
namespace client{
namespace ui{
enum InkEnum{
ID_INK_COLOR,
ID_INK_WIDTH,
};
class InkEventHandler{
...
};
}
}
Now I want this enum in a different namespace,
#include "../client/ui/InkEventHandler.hpp"
using client::ui::InkEventHandler;
namespace ui{
class InkMenu : public ...{
/// I need the ID_INK_COLOR etc here inside the member function.
};
}
however using client::ui::InkEnum is not giving the desigred result.
ofcourse using namespace client::ui; is working, However it opens all
other definitions also, which I may not want.
Moreover I will use InkEnum with InkEventHandler only. Thus can I have
the enum inside the InkEventHandler class definition, so that whenever
I use the class ID_INK_COLOR etc are available?

thanks
abir
 
I

Ian Collins

toton said:
I have an enum in a namespace like,
namespace client{
namespace ui{
enum InkEnum{
ID_INK_COLOR,
ID_INK_WIDTH,
};
class InkEventHandler{
...
};
}
}
Now I want this enum in a different namespace,

Just fully qualify it:

client::ui::InkEnum inkNum;
 
T

toton

Ian said:
Just fully qualify it:

client::ui::InkEnum inkNum;
Where to write this line? inside namespace client::ui ? or in the
InkMenu class definition file? All the enum variables are static
const? What the statement client::ui::InkEnum inkNum; means? They are
synonymous (reference) or copy ?
 
I

Ian Collins

toton said:
Where to write this line? inside namespace client::ui ? or in the
InkMenu class definition file? All the enum variables are static
const? What the statement client::ui::InkEnum inkNum; means? They are
synonymous (reference) or copy ?
Use it anywhere you want a variable of type client::ui::InkEnum, from
your original post, that would be as a member of InkMenu

Provided the appropriate header is included, you can use a fully
qualified name anywhere, just like you do whenever you use anything form
the standard library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top