這裏的規則大拇指說到前置聲明或定義的問題:
正向聲明是標籤,定義是指打開盒子。
是否正在使用的類型的內部信息(即大小,存儲器佈局,成員數據/功能),或者只是其名稱
class Book; // forward declaration of Book. Right now we know nothing about Book's internal info except it's unique ID, i.e. the name of type: Book.
Book *ptr; // OK, pointer's size is fixed and it has nothing to do with Book.
Book **pptr; // Ok, same with previous
ptr->someDataMember = bla; // ERROR, we don't know what is in a Book object.
ptr->callDataFunc(); // ERROR
++ptr; // ERROR, need to know the sizeof Book, since ++ptr equals to (char*)ptr + sizeof(Book)
++pptr; // OK
*pptr++; // OK, *pptr is a Book*, which size is fixed.
**pptr++; // ERROR
template<typename T>
class DontUseT{};
DontUseT<Book> dut; // OK, we don't use Book's internal information here
int foo(Book *b) { return sizeof(b);} // OK
int foo(Book&b) { return 0;} // OK
int foo(Book&b) { return sizeof(Book);} // ERROR
int foo(Book); // OK
int foo(Book) {} // ERROR, inside the definition it's supposed to access its arguments
點擊此鏈接,這將是有幫助的。 http://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration – Vrana