宏定义类 [英] Macro in class definition

查看:133
本文介绍了宏定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类是使用宏定义的。不知道什么是MACRO DEBUG_API的意义在这里。 [我明白#define是用来
打开或关闭一些特定的代码。]但是下面的代码我不能掌握。

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.
     */
};


推荐答案

定义此宏时,可以选择属性将应用于类。这些可以是标准或特定于编译器的属性。

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

您的特定示例很可能是MSVC下DLL头常用模式的一个实例。根据编译时开关, DEBUG_API 将设置为:

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),这将使MSVC生成一个包含类'thunk;这在将库编译为DLL时使用;

  • __ declspec(dllimport),这将使MSVC与上面生成的thunk链接;这是在链接到DLL时使用的;

  • 没有,这不会改变类的行为。这用于静态链接库。

  • __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.

这篇关于宏定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆