C++學習筆記 -虛基類

在C++中使用虛基類的目的是可以在使用間接共同基類時只保留一份成員。因爲一個基類可以在生成一個派生類時作爲虛基類,當生成另一個類時可以不作爲虛基類,這樣就保證了派生類中只保留一份基類的成員。​ ​#include using namespace std; class animal { public: animal(int ia) { a=ia; cout<<"in animal construct
相關文章
相關標籤/搜索