https://www.cnblogs.com/yutongqing/p/6794652.html
typedef和using在定义别名时的区别
template <typename T>
typedef std::vector<T> v;//使用typedef
template <typename T>
using v = std::vector<T>;//使用using
使用typedef时,编译器会报错error: template declaration of ‘typedef’
也就是说,C++编译器不支持使用typedef关键词为模板类设置别名,但是使用using的方式声明一个关键词却是允许的。只是这个是C++11标准才有的,如果在编译时不加上--std=c++11使用新的标准的话,编译器一样会报错。
using 还可以设置函数别名;简写数据类型
#include <iostream>
namespace space //隔离模板,避免冲突
{
template<class T> using ptr = T*;//模板的简写
}
int add(int a, int b)
{
return a + b;
}
typedef int(*ADD)(int a, int b);
using FUNC = int (*)(int a, int b);//别名
//int(*p)(int a,int b)为函数指针,去掉p视为类型。
using co = std::ios_base::fmtflags;//using只可以用于简写数据类型
void main()
{
ADD p=add;
std::cout<<p(1, 2)<<std::endl;
FUNC func = add;
std::cout << func(1, 2) << std::endl;
space::ptr<int> pint(new int(15));//创建一个类型为int的指针 并采用括号()方式对其初始化
std::cout << *pint << " " << pint << std::endl;
std::cin.get();
}