我开始学习 C++ 中的嵌套类,我尝试了一个粘贴在这里的快速代码,以了解嵌套类是如何工作的。但是编译以一些我无法弄清楚的错误结束。
文件:check.cpp
class Outside{
public:
class Inside{
private:
int mInside;
public:
Inside(const int& x):mInside(x){}
};
private:
Inside mOutside(20);
};
int main(void){
Outside o;
return 0;
}
我在编译时遇到的错误g++ -Wall -std=c++11 -o check.out check.cpp
check.cpp:12:25: error: expected parameter declarator
Inside mOutside(20);
^
check.cpp:12:25: error: expected ')'
check.cpp:12:24: note: to match this '('
Inside mOutside(20);
^
我需要这个错误背后的一个很好的解释以及如何克服这个错误。