harttle.github.io
harttle.github.io copied to clipboard
2015/10/03/cpp-template
简洁扼要,非常喜欢
By SelfBoot 2016-08-20T02:36:01Z
博客主题也很棒
By SelfBoot 2016-08-20T02:36:17Z
博主,看到你这里函数模板没有参数,确定这样的函数可以调用吗??
一边看一边复习。看不完了。。先睡。 好想也有一个你这样的博客啊啊啊啊啊。 可惜学会的东西没有兴趣写,不会的又写不出。 如果一开始学什么东西的时候就养成记博客的习惯就好了。
想问一下:
>>11 T max(const T lhs,const T rhs)
10 {
9 return lhs>rhs?lhs:rhs;
8 };
7 template<>
6 class A<int,double>
5 {
4 int data1;
3 double data2;
2 };
1 template<>
>>22 int max(const int lhs,const double rhs)
1 {
2 return lhs>rhs?lhs:rhs;
3 }
这段代码里,22行为什么要是int而不能使double? 写成double的话就显示
no function template matches function template specialization 'max'
三个 T 必须是一样的类型,不一样可以写 template<class T1, class T2>