|
From: dizzy on 16 Apr 2008 02:36 red floyd wrote: > Chris Uzdavinis wrote: >> On Apr 15, 2:27 pm, slatp <songli9...(a)sina.com> wrote: >> >>> //1.h >>> struct A { >>> enum B{a,b,c}; >>> }; >>> >>> //2.h >>> struct C { >>> void func(A::B m); >>> }; >> >>> how to declare enum B? >> >> Currently, enums cannot be forward declared, and so you must pull >> in the definition which is only found in the header you call "1.h" >> You must therefore #include "1.h" >> > > Anybody know if this is subject to change in the draft for C++0x? I > think that forward declaration of enum would be very useful. As per http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2565.html we have "blessed by evolution": N2499 Forward declaration of enumerations Alberto Ganesh Barbati or directly http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2499.pdf I don't understand why there won't be forward declaration support for ANY type (well maybe not any, but any object type such as struct/class, enums, integral types, template instantiations, etc). The important aspect is that the compiler should be able to work with pointers/references to such forward declared types without requiring them to be only of struct/class (I can understand that some pointer types, such as pointers to member functions cannot be treated the same but for pointers to object types it should work). This way then we can reduce "include" clutter alot (without the penalty of an additional layer of indirection as per PIMPL idiom). While I try to forward declare every struct/class instead of including the definitions I can't do it for typedefs that can be to native types for example. -- Dizzy [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
First
|
Prev
|
Pages: 1 2 Prev: Meyers effective C++, templates, np-complete Next: copy constructor not being called |