【发布时间】:2014-12-16 12:04:57
【问题描述】:
是否可以在没有模板专业化的情况下进行如下编译?
template <class T>
class A {
public:
#if std::is_same<T,int>
void has_int() {}
#elif std::is_same<T,char>
void has_char() {}
#endif
};
A<int> a; a.has_int();
A<char> b; b.has_char();
【问题讨论】:
-
您不能将预处理器语句与 c++ 编译器的模板实例化混合使用。
-
你的意思是
A<char> b,对吧?
标签: c++ template-meta-programming