How to use enum from a different namespace?

Discussion in 'C++' started by toton, Aug 23, 2006.

  1. toton

    toton Guest

    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
    toton, Aug 23, 2006
    #1
    1. Advertising

  2. toton

    Ian Collins Guest

    toton wrote:
    > 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;

    --
    Ian Collins.
    Ian Collins, Aug 23, 2006
    #2
    1. Advertising

  3. toton

    toton Guest

    Ian Collins wrote:
    > toton wrote:
    > > 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;

    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 ?
    > --
    > Ian Collins.
    toton, Aug 23, 2006
    #3
  4. toton

    Ian Collins Guest

    toton wrote:
    > Ian Collins wrote:
    >
    >>toton wrote:
    >>
    >>>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;

    >
    > 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.

    --
    Ian Collins.
    Ian Collins, Aug 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Èý¹â
    Replies:
    1
    Views:
    556
    William F. Robertson, Jr.
    Jul 29, 2003
  2. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    520
  3. Jerminia
    Replies:
    3
    Views:
    610
    Roedy Green
    Oct 7, 2005
  4. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    438
    Rolf Magnus
    Nov 13, 2003
  5. toton
    Replies:
    13
    Views:
    813
    mlimber
    Sep 22, 2006
Loading...

Share This Page