This is the mail archive of the cygwin-talk mailing list for the cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: how come #include "*.cpp" works?


On 24 May 2006 18:28, Igor Peshansky wrote:

> On Wed, 24 May 2006, Dave Korn wrote:

>>   Perhaps it would be better to factor out the prototype generation into
>> a separate macro that could be invoked by both instances of "#define
>> CREATABLE_CLASS" ?
> 
> What's wrong with the following?
> 
> #define _CREATABLE_CLASS_DECL(name) \
> class name : virtual public OBJECT
> #define _CREATABLE_CLASS_PROTO(name) \
> extern class OBJECT* create_##name( int argc, const char* argv[] );
> 
> #ifndef CC_NO_CLASS_DECL
> #define CREATABLE_CLASS(name) \
> _CREATABLE_CLASS_PROTO(name) \
> _CREATABLE_CLASS_DECL(name)
> #else
> #define CREATABLE_CLASS(name) \
> _CREATABLE_CLASS_PROTO(name)
> #endif
> 
> and then, in main.cpp:
> 
> #define CC_NO_CLASS_DECL
> #include "objects.def"

  Well, there's nothing wrong with it.  In fact it's exactly what I suggested
doing; you have factored out the prototype generation into a separate macro
called _CREATABLE_CLASS_PROTO.  Sure, you've then gone on to refactor the
separate #definitions of CREATABLE_CLASS into one header that can be included
at each place; with a little more work it would be possible to factor the
table-building definition

#define CREATABLE_CLASS(name) { #name, create_##name },

in as well and then everything would be really nice and well-engineered.


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]