zoukankan      html  css  js  c++  java
  • 第二十三模板 4普通函数,函数模板与具体化函数模板的优先级 简单

    //第二十三模板 4普通函数,函数模板与具体化函数模板的优先级
    //我们定义了个普通函数,然后又定义了一个该函数的模板,接着又重载了这个函数的模板,那么这里就存在一个优先级的问题,即先调用哪里个函数
    //1  普通函数和函数模板的执行次序
    /*#include <iostream>
    using namespace std;
    template <class T>
    void show(T a){cout<<"模板函数"<<endl;}
    void show(int a){cout<<"普通函数"<<endl;}
    int main()
    {
    	int a=5;
    	show(a);//普通函数调用在先,模板函数调用在后
    	//不过这个前提是执行调用函数的必须与普通函数的参数类型
    	show(3.14);
        return 0;
    }*/
    
    // 2 函数模板与具体化函数模板的执行次序
    /*#include <iostream>
    using namespace std;
    template <class T>
    void show(T &a){cout<<"模板函数"<<a<<endl;}
    template<> void show<int>(int&a){ cout<<"具体化模板函数"<<a<<endl;}
    int main()
    {
    	int a=9;
        show(a);
    	float b =2.5;
    	show(b);
    	return 0;
    }*/
    
    //3 具体化函数模板与普通函数的优先级
    /*#include <iostream>
    using namespace std;
    template<class T>
    void show(T a){ cout<<"模板函数"<<endl;}
    template<> void show<int>(int a){ cout<<"具体化模板函数"<<a<<endl;}
    void show(int a){ cout<<"普通函数"<<a<<endl;}
    int main()
    {
    	int a=5;
    	show(a);
        return 0;
    }*/
    //我们看到输出了”普通函数“这说明在函数名,参数类型和参数个数相同的情况,普通函数优先级高于具体化函数模板,而具体化函数模板又高于函数模板
    

      

  • 相关阅读:
    48.Warning: (vsim-3534) [FOFIR]
    47.MIF和COE文件格式
    46.谈谈SDRAM的作用
    45.modelsim仿真include文件
    44.do文件格式
    43.技术与产品的价值
    42.JTAG接口使用注意
    41.使用Chipscope时如何防止reg_wire型信号被优化掉
    40.格雷码与二进制码之间的转换
    39.原码、反码、补码的转换
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2711679.html
Copyright © 2011-2022 走看看