[英]Template Interface Implementation Class C++ error
我在模板繼承方面遇到了一個小問題。
如果我使用模板創建接口類:
template<typename Data>
class InterfaceClass {
private:
public:
virtual Data* foo() = 0; //some function that returns our template type
}
然后,我創建一個實現:
template<typename MoData>
class Implementation : public InterfaceClass<MoData> {
private:
public:
MoData* foo() { MoData* ptr = NULL; return ptr; } //some implementation
}
我似乎在編譯器中無法正常工作。 這不合法嗎?
template<typedef Data>
是不正確的。
你應該用
template<class Data>
要么
template<typename Data>
template <typedef Data>
是錯的,使用
template <typename Data>
請在課程聲明的末尾添加分號。
template<typename Data>
class InterfaceClass {
private:
public:
virtual Data* foo() = 0; //some function that returns our template type
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.