C++ method declaration including a macro(包含宏的 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++ 方法声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包含宏的 C++ 方法声明


- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- C++ 协变模板 2021-01-01