Is this the correct way to typedef an inner class in C++?
class Foo
{
public:
struct A
{
typedef bool Type;
};
struct B
{
typedef int Type;
};
typedef struct Foo::nested;
};
The code compiles under Visual Studio 2008 but I’m not sure if it is indeed a typedef of a nested class, or whether the standard permits it.
Not sure what you are after. If you’d like to typedef one of the existing nested structures, try:
Most likely you want to place the typedef outside of the
Foostruct in this case — you can already accessAfrom within.If you wanted to create a typedef inside
Foofor a nested type of another struct, you could do this:Then you can refer to it as Foo::myNested from outside as well, as long as you declared the typedef public.