zoukankan      html  css  js  c++  java
  • c++11 函数模板的默认模板参数

    c++11 函数模板的默认模板参数

    #define _CRT_SECURE_NO_WARNINGS
    
    #include <iostream>
    #include <string>
    #include <vector>
    #include <map>
    
    // C++11之前,类模板是支持默认的模板参数,却不支持函数模板的默认模板参数
    
    //1、普通函数带默认参数,c++98 编译通过,c++11 编译通过
    void DefParm(int m = 3) {}
    
    //2、类模板是支持默认的模板参数,c++98 编译通过,c++11 编译通过
    template <typename T = int>
    class DefClass {};
    
    //3、函数模板的默认模板参数, c++98 - 编译失败,c++11 - 编译通过
    template <typename T = int>
    void DefTempParm() {}
    
    // 类模板的默认模板参数必须从右往左定义,函数模板的默认模板参数则没这个限定
    template<class T1, class T2 = int> class DefClass1;
    template<class T1 = int, class T2> class DefClass2;   // 无法通过编译
    
    template<class T, int i = 0> class DefClass3;
    template<int i = 0, class T> class DefClass4;         // 无法通过编译
    
    template<class T1 = int, class T2> void DefFunc1(T1 a, T2 b);
    template<int i = 0, class T> void DefFunc2(T a);
    
    
    void mytest()
    {
    
    
        return;
    }
    
    
    int main()
    {
        mytest();
    
        system("pause");
        return 0;
    }
  • 相关阅读:
    hdu 5902 Seam Carving
    hdu 5091 Beam Cannon
    hdu 1542 Atlantis
    hdu 2196 Computer
    第一个爬虫和测试
    排球比赛规则
    第十周博客作业
    科学计算可视化
    用matplotlib绘制图像
    面对对象学习
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/7787478.html
Copyright © 2011-2022 走看看