Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

class is defined using Macro. Not sure what is the significance of MACRO DEBUG_API here. [I understand #define is used to turn on or off some specific set of code.] But below code I cannot grasp. any explanation would be appreciated

#define DEBUG_API

class DEBUG_API Cdebug
{
     public:
     /*
        constructor, methods here.
     */
};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
612 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

Your particular example is most probably an instance of the usual pattern for DLL headers under MSVC. Depending on a compile-time switch, DEBUG_API will be set to either :

  • __declspec(dllexport), which will make MSVC generate a .lib file containing the class' thunk; this is used when compiling the library as a DLL;
  • __declspec(dllimport), which will make MSVC link against the thunk generated above; this is used when linking with the DLL;
  • Nothing, which won't alter the behaviour of the class. This is used to link statically against the library.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...