#include<iostream>
using namespace std;
template<class t1,class t2>
class myclass
{
t1 i;
t2 j;
public :
myclass(t1 x,t2 y)
{
i = x;
j = y;
}
void show()
{
cout<<"i = "<<i<<" j = "<<j<<endl;
}
};
main()
{
myclass<int,double> ob(10,15.2);
myclass<char,char*>ob1('x',"Template");
ob.show();
ob1.show();
}
我想设置第二个模板对象的类型为一个,这样我可以在构造函数中传递一个字符数组,它应该是什么类型?传递字符指针作为模板类型
请参阅 - 我使用GNU GCC编译器集中的g ++编译器来编译我的C++代码。
如果你正在使用字符串,你应该使用'std :: string'。 – NathanOliver
由于使用C++,为什么不通过std :: string?编辑:@NathanOliver速度更快。 :-) – teroi
与字符串是可能的。我已经试过,但不可能与字符数组或字符指针? – Desmond