Defining a macro in a class

Class

defined using a macro. Not sure if MACRO DEBUG_API is here. [I understand that #define is used to enable or disable some specific set of code.] But below the code, I cannot understand. any explanation would be appreciated

#define DEBUG_API class DEBUG_API Cdebug { public: /* constructor, methods here. */ }; 
-2
source share
1 answer

When defining this macro, you can select the attributes that will be applied to the class. These can be standard or compiler-specific attributes.

Your specific example is most likely an instance of the regular template for DLL headers in MSVC. Depending on the compilation time switch, DEBUG_API will be installed either:

  • __declspec(dllexport) , which will make the MSVC generated .lib file containing the thunk class; this is used when compiling the library as a DLL;
  • __declspec(dllimport) , which will make the MSVC link against thunk generated above; this is used when linking to a DLL;
  • Nothing that changes class behavior. This is used to link statics to the library.
+3
source

All Articles