我想定義一個抽象基類,然後將該類型的數組(作爲一個派生類的實例顯然是完整的)作爲函數參數傳遞,但編譯器正在對我大喊大叫。有任何想法嗎?如何通過抽象類型的數組作爲函數參數?
例如(「可測試」是抽象的,「Vecteur」是混凝土):
void Testeur::commencerTest(Testable testables[], int nTestables, string titre) {
cout << "\n" << titre << "\n";
for (int i=0; i < nTestables; i++) {
testables[i].afficher();
}
}
// in main function:
Vecteur v1 = Vecteur(1,2,3);
Vecteur v2 = Vecteur(4,5,6);
Vecteur vecteurs[] = { v1, v2 };
int nVecteurs = 2;
this->commencerTest(vecteurs, nVecteurs, "Some text");
編譯器在上面的代碼中的第一行說invalid abstract type ‘std::Testable’ for ‘testables’
。
我該如何傳遞一個抽象類型的數組作爲函數參數?
錯誤信息意味着你已經在'std'命名空間內定義了'Testable',這是不允許的... – 2012-04-25 11:49:59
你應該給我們定義Testable – 2012-04-25 11:50:43