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?


Dave Korn wrote:
On 24 May 2006 17:00, mwoehlke wrote:
3: A create_<name> function must be written. If all objects were
constructed the same, this could have been lumped into the declaration
CREATABLE_CLASS macro, however not all constructors take the same
arguments, which is why 'create_<name>' takes an argc/argv pair. IOW
this requirement cannot be eliminated.

Are you sure this can't be worked around using varargs macros?


#define CREATABLE_CLASS(name, ...) \
  extern class OBJECT* create_##name( __VA_ARGS__ ); \

Hehe, good try :-), but "no"... First, how would you know how to invoke the create function like that? Second, 'argc' and 'argv' are actually being passed direct from the command line; the idea is that the individual create function deals with the args, so that the upper level doesn't need to know what the args should look like for a particular object type.


=== For declaring an object
#define CREATABLE_CLASS(name) \
extern class OBJECT* create_##name( int argc, const char* argv[] ); \
class name : virtual public OBJECT

=== So main.cpp doesn't need the headers for every class
#undef CREATABLE_CLASS
#define CREATABLE_CLASS(name) \
extern class T_OBJ* create_##name( int argc, const char* argv[] );
#include "objects.def"

Bad idea, I think. You now have two separate bits of code that are generating the prototypes for this set of functions. [snip]

Oh, oops... it's actually 'T_OBJ' in my code; I was trying to replace it with 'OBJECT'. So, 'OBJECT' == 'T_OBJ'.


--
Matthew
Doom doom dooM doo-DooM dOOm DOom doOM... DOOM! -- Gir


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