函数模板
大佬葱^O^
这个作者很懒,什么都没留下…
展开
-
普通函数和函数模板的调用规则
1.如果普通函数和函数模板可以同时使用,则优先调用普通函数2.如果想强制调用函数模板中的内容,可以使用空参数列表3.函数模板可以发生函数重载4.如果函数模板可以产生更好的匹配,那么优先使用函数模板#include<iostream>using namespace std;void func(int a,int b){ cout<<"普通函数调用"<&l...原创 2019-09-29 01:06:32 · 360 阅读 · 0 评论 -
用函数模板实现对int和char类型的数组进行排序
练习#include<iostream>using namespace std;template<typename T>void mySwap(T &a,T &b){ T temp=a; a=b; b=temp;}//选择排序template<typename T>void mySort(T arr[],int len)...原创 2019-09-29 00:47:00 · 643 阅读 · 0 评论 -
模板机制
1.程序的编译过程预处理(Pre-processing)->编译(Compiling)->汇编(Assembling)->链接(Linking)例: hello.c 经过预处理hello.i (将宏展开) hello.i经过编译器hello.s hello.s经过汇编器hello.o hello.o经过链接器hello.exe2.函数模板机制结论1....原创 2019-09-29 01:25:22 · 237 阅读 · 0 评论 -
模板的局限性和解决方法(具体化)
#include<iostream>#include<string>using namespace std;class Person{public: Person(string name,int age) { this->name=name; this->age=age; } string name; int age; ...原创 2019-09-29 01:47:28 · 198 阅读 · 0 评论