class

[C/C++]類別互相引用(Class include each other)

前言


最近開始久違的寫C++程式,然後因為物件上的關係,所以某個A類別會擁有B類別,同時B類別會需要知道A類別

為了能夠壤兩個類別都能夠看到,所以依照直覺的想法,會使兩方的標頭檔(Header file)都會Include彼此,但是此時編譯器卻會發生問題,究竟是為什麼呢? 這樣的想法不是很合理嗎? 

但其實編譯器在解讀時是會出現問題的,究竟哪裡有問題?

經過朋友的解說後,解決了問題也知道了原因,這邊來介紹一下給需要知道的人。

類別互相引用


有時候在開發物件導向的程式時,免不了因為一些OO關係,需要讓某個A類別會擁有B類別,同時B類別會需要知道A類別:

Bay Area Developers - Attend pilot class of Intel's new Parallelism training FREE!

For the past several months we have been hard at work on a new training class for developers. This class teaches the main concepts of threading and scalability to C++ developers new to parallelism. If this means you, and you work in the Bay area, join us for the pilot class, which will be free. Seating is limited, so register early!

When: July 17, 2009
Where: Intel Santa Clara site, building SC12 lobby
Time: 9AM - 4PM, lunch provided
Subscribe to class