我有一个接口C++模板:防止基本模板的实例
std::string
get_string(Source const &s, std::string const &d);
int
get_int(Source const &s, int const &d);
bool
get_bool(Source const &s, bool const &d);
我想改变
template<class T>
T
get(Source const &s, T const &d);
但其中有没有合理的基础模板,所以实际的基础定义是合法但无用的(return d;
)。如果基础实例化,我能做些什么来强制编译时失败?这种情况是否有一种习惯解决方案?
* base模板*是什么意思?另外请记住,功能模板不专门化,但过载。 – 2010-01-12 17:30:41
“基本模板”与“专业化”相对 – 2010-01-12 18:14:45
如果您不想定义“基本模板”,则无需向模板中添加模板。你最初的想法是为各种类型提供重载是正确的。 – 2010-01-12 19:00:04