But of course we shouldn't even think of doing such things, I know, but still this is quite interesting:
class A; //declaration
struct A {...}; //definition
struct B; //declaration
class B {...}; //definition
When I think about it, I don't see any problems if such a thing were really allowed(because struct and class are essentially the same thing). But is it (standard-wise)?
MSVC accepts and compiles it, with a warning.
It is allowed according to the standard, but as some compilers warn about it, it is not very useful.
I believe the warning is/was caused by MSVC using a different name mangling for structs and classes, which would make it even less useful...
On request from @Armen:
7.1.5.3 Elaborated type specifiers, p3
... in any elaborated-type-specifier, the
enum
keyword shall be used to refer to an enumeration (7.2), theunion
class-key shall be used to refer to a union (clause 9), and either theclass
orstruct
class-key shall be used to refer to a class (clause 9), declared using theclass
orstruct
class-key.
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