-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,753
  • 72
  • 57
  • 129

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.

Vinícius
  • 15,498
  • 3
  • 29
  • 53