-1

I try write macros to define some class, but in this case i can not write destructor, because the tilde is a special character for preprocessor.

There is a example:

#define CLASS( cName ) \
class cName \
{ \
public: \
    cName() \
    { \
    \
    } \
    \
    ~cName() \
    { \
    \
    } \ 
};\

How to screen the tilde?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126

1 Answers1

0

This is the proper way to declare it:

#define MAKECLASS(name) \
class name \
{ \
public: \
    name() {} \
    ~name() {} \
};

MAKECLASS(a)

But I should warn you that this is in general a bad idea, why does the design of your program requires this? If it doesn't, you better not using it.

snoopy
  • 14,978
  • 3
  • 25
  • 52