views:

2959

answers:

3

I am using fully qualified name of the enum inside a method in one of my class. But I am getting compiler warning which says "warning C4482: nonstandard extension used: enum 'Foo' used in qualified name". In C++, do we need to use enums without the qualified name? But IMO, that looks ugly.

Any thoughts?

+12  A: 

Yes, enums don't create a new "namespace", the values in the enum are directly available in the surrounding scope. So you get:

enum sample {
  SAMPLE_ONE = 1,
  SAMPLE_TWO = 2
};

int main() {
  std::cout << "one = " << SAMPLE_ONE << std::endl;
  return 0;
}
sth
+4  A: 

Yes. Conceptually enum defines a type, and the possible values of that type. Even though it seems natural, to define enum foo { bar, baz }; and then refer to foo::baz is the same as referring to int::1.

Rob K
A: 

Whereas in Java, Enum can be more viewed as a Class with static members, which are instances of this Class.

Thanks for this information !... I m also coming from Java world..

Ronan Ogor