可能重复:
Forward declaration of nested types/classes in C++有没有办法在C++中预先声明嵌套类?
对于类简单的交叉引用这是feasable到预先声明的类名,并使用它作为参考。这样表示就是一个指针。但是如果我想交叉引用两者的嵌套类(请看下面的例子),我会遇到麻烦,因为似乎没有办法预先声明嵌套类。
所以我的问题是:有没有办法预先声明嵌套类,以便我的例子可以工作?
如果没有:是否有一个共同的解决方法,那不会太丑陋的代码?
// Need to predeclare it to use it inside 'First'
class Second;
class Second::Nested; // Wrong
// Definition for my 'First' class
class First
{
public:
Second::Nested* sested; // I need to use the nested class of the 'Second' class.
// Therefore I need to predeclare the nested class.
class Nested { };
};
// Definition for my 'Second' class
class Second
{
public:
First::Nested* fested; // I need to use the nested class of the 'First' class.
// This is okay.
class Nested { };
};
好的 - 如果我要查找“声明”,我会找到这个答案。 (这是不可能的。)就是这样。谢谢。但是现在我想到一个解决方法。 Unnesting与我的名字空间的另一个'class Nested'类冲突。重命名混淆了界面的用户。 –