0
我想創建一個模板化的基類與非模板派生類。我一直在跟隨umsl.edu/~subramaniana/templates8.html和http://www.cplusplus.com/doc/tutorial/templates/這樣做。繼承的非模板類(模板基礎,非模板派生)的範圍問題
template <class Type>
class Base {
protected:
std::string line;
public:
Base();
};
class DerivedA : public Base<T> {
//error: 'T' was not declared in this scope
//error: template argument 1 is invalid
public:
DerivedA();
protected:
std::list<std::string> A;
};
我想我錯過了一些關於這一切的工作原理,但我似乎無法把握它。
這是完整標頭和實現:
我很困惑。這個想法是,DerivedA類是一個非模板類。我在http://www.umsl.edu/~subramaniana/templates8.html的印象之下,我不應該這樣做,如果我想要一個非模板派生類。 –
該鏈接提供了「模板庫,非模板派生」的概念,你應該在我的答案中適用於我的第二個示例。想想看,T從哪裏來? – billz
我想我明白了。謝謝你的耐心。 –