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++ 方法声明
 
				
         
 
            
        基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				