I want to generate many sub-class which only has little difference, so I want to use macro to simplify my job. The macro define below:
#define DECLARE_SUB_CLASS(sub_class_name, base_class_name, value1) \
class sub_class_name:base_class_name \
{ \
public: \
virtual int initialize(const void *); \
virtual int run(const void *); \
virtual void reset(); \
virtual int output(const char*); \
virtual void terminate(); \
private: \
static const char m_szValue=#value1; \
};
I use it like this:
DECLARE_SUB_CLASS(RTCount13, RTCountBase, 13);
when I compiling with VC2005, it say
error C2065: 'RTCount13' : undeclared identifier
what’s the problem?
Use gcc -E (or similar for other preprocessor)
gcc -E prepro.cxx
You try to assign
"13"to a char.By the way you could also use a template instead of a macro to do the exact same thing your macro did (namely to declare but not define the methods). Here’s a complete (trimmed down) example with separate method definitions.