包含宏的 C++ 方法声明 [英] C++ method declaration including a macro

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

问题描述

我正在使用 QuickFAST 库,在检查它时我发现了这个我似乎并没有真正理解的类声明!我的意思是类名之前的宏名是什么!

I'm using QuickFAST library and while checking it I found this class declaration which I don't seem to really get ! I mean what does a macro name before the class name !

class QuickFAST_Export Message : public FieldSet

我也发现了这个声明

friend void QuickFAST_Export intrusive_ptr_add_ref(const Field * ptr);

再一次我不明白这个声明的用途!

and again I don't get the use of this declaration !

有关详细信息,这里是 QuickFAST_Export.hpp

for more info here's the QuickFAST_Export.hpp

#ifdef _MSC_VER
# pragma once
#endif
#ifndef QUICKFAST_EXPORT_H
#define QUICKFAST_EXPORT_H

// Compile time controls for library generation.  Define with /D or #define
// To produce or use a static library: #define QUICKFAST_HAS_DLL=0
//   Default is to produce/use a DLL
// While building the QUICKFAST_ library: #define QUICKFAST_BUILD_DLL
//   Default is to export symbols from a pre-built QUICKFAST DLL
//
// Within QUICKFAST use the QuickFAST_Export macro where a __declspec is needed.

#if defined (_WIN32)

#  if !defined (QUICKFAST_HAS_DLL)
#    define QUICKFAST_HAS_DLL 1
#  endif /* ! QUICKFAST_HAS_DLL */

#  if defined (QUICKFAST_HAS_DLL) && (QUICKFAST_HAS_DLL == 1)
#    if defined (QUICKFAST_BUILD_DLL)
#      define QuickFAST_Export __declspec(dllexport)
#    else /* QUICKFAST_BUILD_DLL */
#      define QuickFAST_Export __declspec(dllimport)
#    endif /* QUICKFAST_BUILD_DLL */
#  else /* QUICKFAST_HAS_DLL == 1 */
#    define QuickFAST_Export
#  endif /* QUICKFAST_HAS_DLL == 1 */

#  else /* !_WIN32 */

推荐答案

表示类是导出还是导入,取决于构建的模块.

It means that the class is either exported or imported, depending on which module is built.

如果QUICKFAST_HAS_DLL被定义并且等于1,这意味着模块被构建为一个DLL.要使用外部功能,必须导出类和方法.

If QUICKFAST_HAS_DLL is defined and equal to 1, it means that the module is built as a DLL. To use functionalities from the outside, classes and methods have to be exported.

在模块内部,定义了 QUICKFAST_BUILD_DLL.因此,当您构建模块时,QuickFAST_Export 会扩展为 __declspec(dllexport).您的类定义变为:

Inside the module, QUICKFAST_BUILD_DLL is defined. So when you build the module, QuickFAST_Export expands to __declspec(dllexport). Your class definition becomes:

class __declspec(dllexport) Message : public FieldSet

当您包含来自不同模块的标头时,未定义 QUICKFAST_BUILD_DLL,因此宏扩展为 __declspec(dllimport),您的类定义为:p>

When you include the header from a different module, QUICKFAST_BUILD_DLL is not defined, so the macro expands to __declspec(dllimport), and your class definition to:

class __declspec(dllimport) Message : public FieldSet

这篇关于包含宏的 C++ 方法声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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