c++模板的定制问题
#include<iostream>template<class T1,class T2>
class Mytemplate
{
private:
T1 obj1;
T2 obj2;
public:
Mytemplate(T1 o1,T2 o2):obj1(o1),obj2(o2){}
void display()
{
std::cout<<"object display:"<<std::endl;
std::cout<<"----------------"<<std::endl;
std::cout<<"object 1: "<<obj1<<std::endl;
std::cout<<"object 2: "<<obj2<<std::endl;
std::cout<<std::endl;
}
};
template<class T1>
class Mytemplate<T1,char>
{
private:
T1 obj1,obj2;
public:
Mytemplate(T1 o1,char c):obj1(o1),obj2(o1)
{
obj2+=(int)c;
}
void display()
{
std::cout<<"object display:"<<std::endl;
std::cout<<"----------------"<<std::endl;
std::cout<<"object 1: "<<obj1<<std::endl;
std::cout<<"object 2: "<<obj2<<std::endl;
std::cout<<std::endl;
}
};
int main()
{
Mytemplate<int,int> mt1(10,20);
Mytemplate<int,char> mt2(10,'b');
mt1.display();
mt2.display();
return 0;
}
d:\source\c++\标准c++\pr15010\aaa.cpp(40) : error C2989: 'Mytemplate<T1,char>' : template class has already been defined as a non-template class
d:\source\c++\标准c++\pr15010\aaa.cpp(40) : error C2988: unrecognizable template declaration/definition
Error executing cl.exe.
谁知道是怎么回事啊???!