C++ using

13 篇文章 1 订阅

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?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值