[英]C++ syntax/legality of inheriting from a template while also specifying type
[英]Inheriting an Abstract Template Class in C++ while specifying the type
說我有一個模板,抽象類:
template <class T>
class MyClass {
public:
virtual bool foo(const T a, const T b) = 0;
}
還有一個想要繼承的類,同時擺脫了模板:
class MyInheritor : public MyClass<int *> {
public:
bool foo(const int* a, const int* b) { /* stuff */ }
}
上面沒有讓我實例化MyInheritor,說它是一個抽象類。 如何覆蓋純虛擬方法?
因為您在這里沒有覆蓋任何內容:const應用於int而不應用於int的指針。
這是您可能想要的固定版本:
class MyInheritorFixed : public MyClass<int *> {
bool foo(int* const a, int* const b) override { return true; }
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.