【发布时间】:2019-05-23 06:29:20
【问题描述】:
我正在尝试使用结构和子结构制作通用模板, 但我的代码无法推断出正确的模板。 这是我的代码的抽象
#include <iostream>
using namespace std;
struct A{
};
struct B{
};
struct AA:public A{
};
struct BB:public B{
};
template<class container>
class Base{
};
template<class container>
class Derived:Base<container>{
Derived() = delete;
};
template<>
class Derived<A>:Base<A>{
};
template<>
class Derived<B>:Base<B>{
};
int main() {
Derived<AA> a;
return 0;
}
出现错误
error: call to deleted constructor of 'Derived<AA>'
我希望struct A 及其子类可以与
template<>
class Derived<A>:Base<A>{
};
我该怎么做,或者我应该参考什么材料? 谢谢帮忙!
【问题讨论】:
标签: c++ templates inheritance polymorphism