不能向前聲明一樣,嵌套類。
取決於你想要做什麼,也許你可以使用一個命名空間,而不是在外層上的類。您可以轉發,聲明這樣一類沒有問題:
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