一、代码
成员模板:一个自身是模板的成员。
#include <iostream>
#include <typeinfo>
using namespace std;
//成员模板
template <typename T>
class Array
{
public:
template <typename T1>
void output(T thistype, T1 othertype);
};
//成员模板
template <typename T>
template <typename T1>
void Array<T>::output(T thistype, T1 othertype)
{
cout<<"thistype is "<<typeid(thistype).name()<<", othertype is "<<typeid(othertype).name()<<endl;
}
int main(int argc, char*argv[])
{
Array<int> arr;
arr.output(10, "hello world");
arr.output(20, 8.8);
arr.output(30, false);
return 0;
}
二、输出结果
不同编译器typeid().name()返回的结果不同。
Linux gcc下输出结果:
Windows VS下输出结果: