【发布时间】:2010-01-06 12:46:52
【问题描述】:
假设我有课程:
class Base{};
class A: public Base{
int i;
};
class B:public Base{
bool b;
};
现在我想定义一个模板类:
template < typename T1, typename T2 >
class BasePair{
T1 first;
T2 second;
};
但我想将其定义为只有 Base 类的后代可以用作模板参数。
我该怎么做?
【问题讨论】:
-
您需要更正模板语法。你的意思是A和B是私人派生的吗?
标签: c++ generics inheritance templates