I have a set of enumeration values ββdefined in the "Foo" class (below).
namespace Fii
{
class Foo
{
struct Bar
{
enum Baz
{
BAZ1,
BAZ2,
BAZ3
};
};
};
};
I use struct to reduce the range of the Baz enumeration, and also show that there is a group of related values.
My goal is to assign an enum type value to a variable. Using the class definition above, you can do the following:
Fii::Foo::Bar::Baz myValue = Fii::Foo::Bar::BAZ1 (Works in both C++98 and C++11)
However, I feel that:
- At first glance, myValue seems to be initialized as Fii :: Foo :: Bar, but this is only because the enumeration is a hack for grouping related constants in the parent (Bar in this case)
To increase availability, I re-named the code:
namespace Fii
{
class Foo
{
enum Baz
{
BAZ1,
BAZ2,
BAZ3
};
};
};
Using this new class definition, you can do the following:
Fii::Foo::Baz myValue = Fii::Foo::Baz::BAZ1 (Works in C++11 only)
Fii::Foo::Baz myValue = Fii::Foo::BAZ1 (Should work on C++98 and C++11 - not tested)
Q1) Why is Fii :: Foo :: Bar :: Baz myValue = Fii :: Foo :: Baz :: BAZ1 only works in C ++ 11?
Q2) ++ 98 Fii:: Foo:: Baz myValue = Fii:: Foo:: Baz:: BAZ1? , .
:
- Clang ++ 11
- Xcode 4
- Mac OS OS 10.8