编辑代码

#include <iostream>
#include<map>
using namespace std;
//c++11 using可以用来定义别名,类似typedef.
int mytest(int a,string b)
{
    cout<<"a: "<<a<<",b:"<<b<<endl;
    return 0;
}
//定义函数指针类型
typedef int(*func)(int,string);
using func1=int(*)(int,string);


// template<class T>
// typedef map<int,T> mapType;  //err

//通过类或结构体可以实现给容器模板起别名。
template<class T>
struct MyMap
{
    typedef map<int,T> mapType;  

};

//通过using给模板起别名。

template<class T>
using MMap = map<int,T>;


void test()
{   
    
    typedef int t1;
    t1 a=10;
    t1 b=5;
    using t2=int;
    t2 a1=3;
    func f=mytest;
    func1 f1=mytest;
    f(10,"hello");
    f1(10,"hello");

    //map int-int  int-double  int -string    第二个参数变的需求,直接用模板不行。 
    MyMap<int>::mapType mm1;
    MyMap<double>::mapType mm2;
    MyMap<string>::mapType mm3;

    MMap<int> mm4;
    MMap<double> mm5;
    MMap<string> mm6;
}

int main() {
    test();
	return 0;
}