In C++, is it semantically equivalent to have a named struct
struct S { int x; };
vs. a type alias for an unnamed struct
using S = struct { int x; }
?
Are there any differences in using the first or second version of S or are those variants completely interchangeable? Or is it very likely that some compiler have issues with the second version?
The using
keyword with that context was introduced in C++11 which means that older compilers that work with the C++98 standard will not be able to compile it.
You will also not be able to forward declare your struct.
As such, no they are not 100% equivalent; but in some cases the using could be substituted for the usual declaration.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.