Using enum inside types - Compiler warning C4482 C++

Navaneeth K N picture Navaneeth K N · Feb 5, 2009 · Viewed 43.3k times · Source

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?

Answer

sth picture sth · Feb 5, 2009

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;
}