c++11 之模板定义别名(using)

C++11标准中可以为模板定义别名,比如

template<typename T>
using ptr=std::shared_ptr<T>;

//这里模板定义ptr<T>为智能指针std::shared_ptr<T>定义的别名
所以实际应用中可以借此来简化代码,比如

#include<memory>
#include<string>
using namespace std;
template<typename T>
using ptr=std::shared_ptr<T>;
 
int main()
{
    //这里借助模板别名,用ptr<string> 来代替std::shared_ptr<string>
    ptr<string> p=std::make_shared<std::string>();
    return 0;
}


 
 

猜你喜欢

转载自blog.csdn.net/qq_41598072/article/details/84890812