相关疑难解决方法(0)

什么时候应该在C++中使用类vs结构?

在什么情况下在C++中使用structvs a 更好class

c++ oop struct ooad class

895
推荐指数
15
解决办法
38万
查看次数

在C++ 11中'typedef'和'using'有什么区别?

我知道在C++ 11中我们现在可以using用来写类型别名,比如typedefs:

typedef int MyInt;
Run Code Online (Sandbox Code Playgroud)

从我的理解,相当于:

using MyInt = int;
Run Code Online (Sandbox Code Playgroud)

这种新语法来自于努力表达" template typedef":

template< class T > using MyType = AnotherType< T, MyAllocatorType >;
Run Code Online (Sandbox Code Playgroud)

但是,对于前两个非模板示例,标准中是否还有其他细微差别?例如,typedefs以"弱"方式进行别名.也就是说,它不会创建新类型,而只会创建新名称(这些名称之间隐含的转换).

它是否与using生成新类型相同或是否生成新类型?有什么不同吗?

c++ typedef using-declaration c++11

833
推荐指数
8
解决办法
25万
查看次数

标签 统计

c++ ×2

c++11 ×1

class ×1

ooad ×1

oop ×1

struct ×1

typedef ×1

using-declaration ×1