Home > Backend Development > C++ > Can `using` Completely Replace `typedef` in C 11 for Non-Template Types?

Can `using` Completely Replace `typedef` in C 11 for Non-Template Types?

Barbara Streisand
Release: 2024-12-23 18:57:13
Original
328 people have browsed it

Can `using` Completely Replace `typedef` in C  11 for Non-Template Types?

Can 'using' Replace 'typedef' in C 11?

In C 11, 'using' can now define type aliases similar to 'typedefs':

typedef int MyInt; // Equivalent to:
using MyInt = int;
Copy after login

While 'using' was initially introduced to support template typedefs:

template< class T > using MyType = AnotherType< T, MyAllocatorType >;
Copy after login

this raises the question of whether there are any subtle differences between 'typedef' and 'using' when handling non-template types.

Aliasing Behavior and Implications

Both 'typedef' and 'using' create an alias or new name for an existing type, rather than defining a new type. This means that conversions between the alias and the original type are implicit.

Therefore, there is no difference between 'typedef' and 'using' in terms of their aliasing behavior. Both constructs create weak aliases that reference the same underlying type.

The above is the detailed content of Can `using` Completely Replace `typedef` in C 11 for Non-Template Types?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template