我想聲明和使用B類A類 的內部和定義31b的外側A.
我知道一個事實,這是可能的,因爲Bjarne的Stroustrup的
使用這他的書「The C++ programming language」
(第293頁,例如String和Srep類)。C++嵌套類向前聲明錯誤
所以這是我最小的代碼引起的問題
class A{
struct B; // forward declaration
B* c;
A() { c->i; }
};
struct A::B {
/*
* we define struct B like this becuase it
* was first declared in the namespace A
*/
int i;
};
int main() {
}
這個代碼給出了G ++以下編譯錯誤:
tst.cpp: In constructor ‘A::A()’:
tst.cpp:5: error: invalid use of undefined type ‘struct A::B’
tst.cpp:3: error: forward declaration of ‘struct A::B’
我想看看C++ FAQ和closeset我得到的是here和here,但
那些不適用於我的情況。
我也從這裏read this,但它不能解決我的問題。在這個
是定義後`inline`關鍵字定義函數爲內聯,該工作 謝謝:) – xxxxxxx 2008-11-21 23:52:04