在定义成员函数时,使用内部类的typedef的正确语法是什么?从下面的代码中可以看出,我正在尝试在其ctor定义中使用内部类的typedef,但我找不到正确的语法 - 有人可以帮忙吗?
#include <iostream>
class Outer
{
public:
Outer( int a );
class ThisInnerClassNameIsAwfullyLong
{
public:
ThisInnerClassNameIsAwfullyLong( int a );
private:
int a_;
};
typedef ThisInnerClassNameIsAwfullyLong Inner;
private:
Inner inner_;
};
Outer::Outer( int a )
: inner_( a )
{
}
//Outer::Inner::Inner( int a ) // This doesn't compile
//Outer::Inner::Outer::Inner( int a ) // This looks like nonsense, but I tried it anyway. It does not compile, obviously.
Outer::ThisInnerClassNameIsAwfullyLong::ThisInnerClassNameIsAwfullyLong( int a ) // This compiles.
: a_( a )
{
}
int main( int argc, char* argv[] )
{
Outer::Inner inner( 2 ); // Although this looks "similar to" line 27, it compiles.
std::cout << "hello, world." << std::endl;
return 0;
}
我还想问为什么在Outer::Inner
中使用main()
,与编译中断第27行类似,编译,而后者则不好。