ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C++ using

2020-01-22 21:04:14  阅读:16  来源: 互联网

标签:typedef 參考 What C++ int using



C++ using

using

using與C語言裡的typedef都是用來宣告別名的,那麼他們兩者有什麼差別呢?根據What is the difference between ‘typedef’ and ‘using’ in C++11?:

They(typedef and using) are largely the same, except that:
The alias declaration(using) is compatible with templates, whereas the C style typedef is not.

以下兩種寫法等價:

typedef int MyInt;
using MyInt = int;

至於在使用了template的情況下,則一定要用using,以下代碼來自TensorRT/samples/common/buffers.h

using DeviceBuffer = GenericBuffer<DeviceAllocator, DeviceFree>;
using HostBuffer = GenericBuffer<HostAllocator, HostFree>;

參考連結

What is the difference between ‘typedef’ and ‘using’ in C++11?

keineahnung2345 发布了74 篇原创文章 · 获赞 9 · 访问量 5万+ 私信 关注

标签:typedef,參考,What,C++,int,using
来源: https://blog.csdn.net/keineahnung2345/article/details/104072444

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有