Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.


You 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).



Thanks 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


Although it should be possible per standard C++, Microsoft's compilers have trouble dealing with it.


Although I can't currently support my claim, I swear that I have gotten compiler warnings for doing so.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: