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;
    }*/
    //通过该实例我们可以看出,编译器在执行函数时会选择最匹配的函数模板,假如只存在一个这样的函数模板,那么就选择它,假哪存在多个符合要求的函数,并且其中有非模板函数,即普通函数,那么选择普通函数,假哪这多个符合要求的函数都是模板,但是其中有一个具体化函数模板,那么选择具体函数模板,假如没有具体化函数模板,那么选择更加接近要求的重载函数,假如都不接近要求或者不存在匹配的函数,那么函数的调用将是不确定的
    

      

  • 相关阅读:
    Seial port API and tool
    Simple HTTPD
    VC与Cygwin的结合
    zlib
    嵌入式开发系统编程文件格式解析
    ZB4O
    Wireshark基本介绍和学习TCP三次握手
    freeware
    Console2 A Better Windows Command Prompt
    iniparser
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2711680.html
Copyright © 2011-2022 走看看