【发布时间】:2013-03-04 10:51:52
【问题描述】:
// template specialization
#include <iostream>
using namespace std;
// class template:
template <class T>
class mycontainer {
T element;
public:
mycontainer (T arg) {element=arg;}
T increase () {
//if(T.type==int)//how to do this or something similar?
//do this if an int
return ++element;
//if(T.type==char)
//if ((element>='a')&&(element<='z'))
//element+='A'-'a';
//return element;
}
};
我知道如何编写模板特化并为 char 类型做一个单独的整个类定义。
但是,如果我想在一个代码块中处理所有事情呢?
如何检查 T 是 int 还是 char?
【问题讨论】: