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

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

c++ - Macro in class definition

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

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

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...