64,639
社区成员
发帖
与我相关
我的任务
分享
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}
[/quote]
不行,你的这个连编译都通过不了。[/quote]
怎么不能通过了,你编译器太老了吧[/quote]
你的可以通过吗?你试过了吗?[/quote]
VS2012下没问题,10没试过
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}
int main()
{
cout<<Add<int, int>(1,2)<<endl;
cout <<Add<char*, char>('a', 'b')<<endl; //这个输出后面是乱码,因为不是\0结尾
getchar();
return 0;
}
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}
[/quote]
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}
[/quote]
不行,你的这个连编译都通过不了。[/quote]
怎么不能通过了,你编译器太老了吧[/quote]
你的可以通过吗?你试过了吗?
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}
[/quote]
不行,你的这个连编译都通过不了。[/quote]
怎么不能通过了,你编译器太老了吧
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}
[/quote]
不行,你的这个连编译都通过不了。
template <typename Tout, typename Tin>
Tout Add(Tin x, Tin y)
{
return x + y;
}
template <>
char* Add<char*, char>(char x, char y)
{
char* p = new char[2];
p[0] = x;
p[1] = y;
return p;
}