Advertisement

C++标准模板库(STL)

阅读量:

模板 Template

复制代码
    #include<iostream>
    using namespace std;
    
    template <typename T>
    T func(T a,T b){
    return a+b;
    }
    
    int main(){
    int a=1;
    int b=2;
    float c=3.0;
    float d=4.5;
    
    cout << " a+b= " << func<int>(a,b) << endl;
    cout << " c+d= " << func<float>(c,d) << endl;
    
    return 0;
    
    }
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
复制代码
     a+b= 3
     c+d= 7.5
    
    
      
      
    

class的模板

复制代码

全部评论 (0)

还没有任何评论哟~