harttle.github.io icon indicating copy to clipboard operation
harttle.github.io copied to clipboard

2015/10/03/cpp-template

Open harttle opened this issue 7 years ago • 6 comments

C++模板的偏特化与全特化 - Harttle Land

http://harttle.land/2015/10/03/cpp-template.html

harttle avatar May 02 '18 18:05 harttle

简洁扼要,非常喜欢

By SelfBoot 2016-08-20T02:36:01Z

harttle avatar May 02 '18 18:05 harttle

博客主题也很棒

By SelfBoot 2016-08-20T02:36:17Z

harttle avatar May 02 '18 18:05 harttle

博主,看到你这里函数模板没有参数,确定这样的函数可以调用吗??

aaron-ai avatar May 17 '18 05:05 aaron-ai

一边看一边复习。看不完了。。先睡。 好想也有一个你这样的博客啊啊啊啊啊。 可惜学会的东西没有兴趣写,不会的又写不出。 如果一开始学什么东西的时候就养成记博客的习惯就好了。

ghost avatar May 21 '18 17:05 ghost

想问一下:

>>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'

ghost avatar May 23 '18 02:05 ghost

三个 T 必须是一样的类型,不一样可以写 template<class T1, class T2>

harttle avatar May 23 '18 04:05 harttle