Is there any difference in any aspect (syntactic limitation, performance, etc.) between the following two definitions?
using Foo = struct { int a, b, c; };
struct Foo { int a, b, c; };
(I'm asking because the first form is aesthetically more uniform when put among a lot of using
declarations.)
EDIT: The post linked to in the comment doesn't exactly answer my question. I'm more concerned about how the above two definitions differ in terms of usage, whereas that post mainly answers how they are different in terms of, well, what they are, I think.
In C++, a typedef name must be different from any class type name declared within the same scope. If the typedef name is the same as a class type name, it can only be so if that typedef is a synonym of the class name. A C++ class defined in a typedef definition without being named is given a dummy name.
A class with no name provided is known as an anonymous class in c++. An anonymous class is a special class with one basic property. As there is no name given to the class there is no constructor allocated to it, though a destructor is there for deallocating the memory block.
Anonymous classes: Cannot have a constructor or destructor.
Here are some differences I can think of:
final
.struct Foo
can be declared in the same declarative region as a function or variable named Foo
, although, obviously, you shouldn't do this. using Foo = ...
does not allow you this freedom.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With