zoukankan      html  css  js  c++  java
  • 第二十三模板 5函数模板的匹配 简单

    //第二十三模板 5函数模板的匹配
    /*#include <iostream>
    using namespace std;
    struct people
    {
       char name[10];
       int age;
    };
    template <class T>
    void show(T t[], int n)
    {
        cout<<"执行函数模板void show(T t[], int n) "<<endl;
    	for(int i=0; i<n; i++)
    		cout<<t[i]<<' ';
    	cout<<endl;
    }
    template <class T>
    void show(T * t[], int n)
    {
        cout<<"执行函数模板void show(T * t[], int n) "<<endl;
    	for(int i=0; i<n; i++)
    		cout<<*t[i]<<' ';
    	cout<<endl;
    }
    int main()
    {
    	 int num[2]={13,31};
    	 people list[3]={{"Jack",21},{"Mick",24},{"Tom",18}};
    	 int *pd[3];
    	 for(int i=0; i<3; i++)
    		  pd[i] = &list[i].age;
    	 show(num,2);
    	 show(pd,3);
         return 0;
    }*/
    //通过该实例我们可以看出,编译器在执行函数时会选择最匹配的函数模板,假如只存在一个这样的函数模板,那么就选择它,假哪存在多个符合要求的函数,并且其中有非模板函数,即普通函数,那么选择普通函数,假哪这多个符合要求的函数都是模板,但是其中有一个具体化函数模板,那么选择具体函数模板,假如没有具体化函数模板,那么选择更加接近要求的重载函数,假如都不接近要求或者不存在匹配的函数,那么函数的调用将是不确定的
    

      

  • 相关阅读:
    JS-instanceof 与typeof
    JS-面向对象相关
    spark job源代码物理执行图实战
    堆(heap)和栈(stack)的区别
    sql developer怎样调试Pipelined
    oracle dbms_output 在java中输出
    sed 用法笔记
    oracle 怎样建自增长字段
    python学习笔记--split与join用法
    如何开启php报错
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2711680.html
Copyright © 2011-2022 走看看