C ++方法声明包括宏 [英] C++ method declaration including a macro
问题描述
我使用QuickFAST库,而检查它,我发现这个类声明,我似乎不真的得到!我的意思是类名前有一个宏名称!
类QuickFAST_Export消息:public FieldSet
也找到这个声明
friend void QuickFAST_Export intrusive_ptr_add_ref(const Field * ptr);
,我再也没有使用这个声明!
如需更多资讯,请参阅这里的QuickFAST_Export.hpp
#ifdef _MSC_VER
#pragma once
#endif
#ifndef QUICKFAST_EXPORT_H
#define QUICKFAST_EXPORT_H
//编译库生成的时间控件。使用/ D或#define
定义//生成或使用静态库:#define QUICKFAST_HAS_DLL = 0
//默认生成/使用DLL
//构建QUICKFAST_库:#define QUICKFAST_BUILD_DLL
//默认是从预建的QUICKFAST DLL导出符号
//
//在QUICKFAST中使用QuickFAST_Export宏,其中需要__declspec。
#if defined(_WIN32)
#if!defined(QUICKFAST_HAS_DLL)
#define QUICKFAST_HAS_DLL 1
#endif / *! QUICKFAST_HAS_DLL * /
#如果已定义(QUICKFAST_HAS_DLL)&& (QUICKFAST_HAS_DLL == 1)
#如果定义(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 * /
解决方案
如果定义了
QUICKFAST_HAS_DLL
,那么该类将被导出或导入并且等于1,则意味着该模块被构建为DLL。要使用外部函数,必须导出类和方法。
在模块中定义了
QUICKFAST_BUILD_DLL
。因此,当您构建模块时,QuickFAST_Export
扩展为__ declspec(dllexport)
。你的类定义变成:class __declspec(dllexport)消息:public FieldSet
当您包含来自不同模块的标题时,未定义
QUICKFAST_BUILD_DLL
__ declspec(dllimport)
,您的类别定义为:class __declspec (dllimport)消息:public FieldSet
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
also I found this declaration
friend void QuickFAST_Export intrusive_ptr_add_ref(const Field * ptr);
and again I don't get the use of this declaration !
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.
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.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
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屋!