Can i write code like this
class Foo
{
typedef Foo type;
};
I don't see any limitations in standard about this.
Can i write code like this
class Foo
{
typedef Foo type;
};
I don't see any limitations in standard about this.
NOTE: Compiler: Apple GCC, OS: OSX 10.7
GCC finds nothing wrong with this, and I am able to use the type type
later in the definition of Foo. However, you cannot use the type type
outside of Foo.
It is possible to write that code. type
and Foo
are not reserved words, and C++ allows to define types within structs or classes. In fact, they are heavily used in templates for metaprogramming and type introspection. See How do you understand dependent names in C++ for further details on that aspect of the language.