简体   繁体   English

这个额外的关键字在这个 C++ 类声明中是什么意思?

[英]What does this extra keyword mean in this c++ class declaration?

I'm looking at some C++ code which declares a class like this:我正在查看一些声明如下类的 C++ 代码:

class LIBSBML_EXTERN LayoutModelPlugin : public SBasePlugin

What is the LIBSBML_EXTERN keyword for? LIBSBML_EXTERN 关键字的用途是什么?

It's a macro.这是一个宏。 I'm not sure exactly what libraries you're using, but likely it's the macro with the definition you can see here: https://github.com/copasi/copasi-dependencies/blob/master/src/libSBML/src/sbml/common/extern.h我不确定您正在使用哪些库,但可能是您可以在此处看到的定义的宏: https : //github.com/copasi/copasi-dependencies/blob/master/src/libSBML/src/ sbml/common/extern.h

#if ( ! defined LIBSBML_STATIC )
/**
 * The following ifdef block is the standard way of creating macros which
 * make exporting from a DLL simpler. All files within this DLL are
 * compiled with the LIBSBML_EXPORTS symbol defined on the command line.
 * This symbol should not be defined on any project that uses this
 * DLL. This way any other project whose source files include this file see
 * LIBSBML_EXTERN functions as being imported from a DLL, wheras this DLL
 * sees symbols defined with this macro as being exported.
 *
 * (From Andrew Finney's sbwdefs.h, with "SBW" replaced by "LIBSBML" :)
 */
#if defined(LIBSBML_EXPORTS)
#  define LIBSBML_EXTERN __declspec(dllexport)
#else
#  define LIBSBML_EXTERN __declspec(dllimport)
#endif

#else
#  define LIBSBML_EXTERN
#endif  /* LIBSBML_STATIC */

It is used to interface the class definition with DLLs, if required.如果需要,它用于将类定义与 DLL 接口。

It is a macro, something that you would define like this:它是一个宏,您可以这样定义:

#define LIBSBML_EXTERN whatever

where whatever is what the compiler puts in place of LIBSBML_EXTERN before compiling.其中, whatever是什么样的编译器看跌期权代替LIBSBML_EXTERN编译之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM