不能向前声明一样,嵌套类。
取决于你想要做什么,也许你可以使用一个命名空间,而不是在外层上的类。您可以转发,声明这样一类没有问题:
namespace Outer {
struct Inner;
};
Outer::Inner* sweets; // Outer::Inner is incomplete so
// I can only make a pointer to it
如果你的外在绝对必须是一个类,你不能鞋拔到一个命名空间,那么你所需要的外部是一个在您转发声明Inner的上下文中的完整类型。
class Outer
{
class Inner; // Inner forward-declared
}; // Outer is fully-defined now
Outer yes; // Outer is complete, you can make instances of it
Outer::Inner* fun; // Inner is incomplete, you can only make
// pointers/references to it
class Outer::Inner
{
}; // now Inner is fully-defined too
Outer::Inner win; // Now I can make instances of Inner too
代码如下的循环链“外包含外包含外包含外......” – Muxecoid 2010-04-08 13:56:15
可能的重复[如何转发声明一个内部类?](http://stackoverflow.com/questions/1021793/how-do-i-forward-declare-an-inner-class) – 2015-07-15 09:34:07