c++11 之模板定义别名(using)
生活随笔
收集整理的這篇文章主要介紹了
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;
}
?
?
總結
以上是生活随笔為你收集整理的c++11 之模板定义别名(using)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: There's no Qt versio
- 下一篇: 在析构函数中delete this指针问