Enum "copy" problem

Posted by f0b0s on Stack Overflow See other posts from Stack Overflow or by f0b0s
Published on 2010-04-07T22:49:43Z Indexed on 2010/04/07 22:53 UTC
Read the original article Hit count: 280

Filed under:
|
|
|

Hi all! I have a class, let's call it A. It has a enum (E) and a method Foo(E e), with gets E in the arguments. I want to write a wrapper (decorator) W for A. So it'll have its own method Foo(A::E). But I want to have some kind of encapsulation, so this method should defined as Foo(F f), where F is another enum defined in W, that can be converted to A::E. For example:

class A
{
  public:
    enum E { ONE, TWO, THREE };
    void Foo(E e);  
};

class B
{
  //enum F; // ???
  void Foo(F f)
  {
    a_.Foo(f);
  }

  private:
    A a_;
};

How F should be defined? I don't want to copy value like this:

enum F { ONE = A::ONE, TWO = A::TWO, THREE = A::THREE };

because its a potential error in the near feature. Is the typedef definition:

typedef A::E F;

is the best decision? Is it legal?

© Stack Overflow or respective owner

Related posts about c++

Related posts about enum