3 ms·
> When forward declaring a class/struct, you must use the same keyword which it was declared with. Wrong. struct Foo; class Foo { }; int mai
by zokier 13y ago
> When forward declaring a class/struct, you must use the same keyword which it was declared with.
Wrong.
struct Foo;
class Foo {
};
int main(int, char**) {
Foo f;
}
compiles cleanly with -ansi -pedantic -Wall -Wextra besides warning about unused variable.
- nicolasgz 13y agoAlthough I can't currently support my claim, I swear that I have gotten compiler warnings for doing so.
- nicolasgz 13y agoSome relevant discussion here: http://cboard.cprogramming.com/cplusplus-programming/134827-gcc-lets-you-forward-declare-struct-class-name.html http://cboard.cprogramming.com/cplusplus-programming/134827-...
- Patient0 13y agoThanks for confirming - this was the one statement that struck me as wrong too but I don't have a C++ compiler readily to hand on my iphone
- nicolasgz 13y agoAlthough it should be possible per standard C++, Microsoft's compilers have trouble dealing with it.
- jzwinck 13y agoYou don't mention what compiler you tested it with, but both Clang and MSVC are capable of spotting the mismatch (and sometimes even fail to compile it).