C ++中类定义前面的宏

时间:2018-11-04 20:09:35

标签: c++ class

谁能解释下面的类声明前面的宏术语(以下代码中的OPENRTI_LOCAL术语)做什么?请忽略以下示例的上下文。我正在寻找以下cpp类声明类型的一般解释。

namespace OpenRTI {
  class OPENRTI_LOCAL RTI1516ETestAmbassador : public RTITest::Ambassador, 
  public rti1516e::FederateAmbassador {
  ......
  }
}

2 个答案:

答案 0 :(得分:0)

这是一个特定于库的术语,您需要在OpenRTI库中查找。通常,此位置可能会有一个指定符,例如标准alignas,因此宏可能会扩展到这样的指定符或特定于供应商的属性,或者仅扩展为空字符串。

答案 1 :(得分:0)

检查OpenRTI's source code,看起来它只是表明简单对象在编译为共享库时是隐藏的:

// Now we use the generic helper definitions above to define OPENRTI_API and OPENRTI_LOCAL.
// OPENRTI_LOCAL is used for non-api symbols.

#ifdef OPENRTI_DLL // defined if OPENRTI is compiled as a DLL
# define OPENRTI_LOCAL OPENRTI_HELPER_DLL_LOCAL
#else // OPENRTI_DLL is not defined: this means OPENRTI is a static lib.
# define OPENRTI_LOCAL
#endif // OPENRTI_DLL

OPENRTI_HELPER_DLL_LOCAL是:

// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
# define OPENRTI_HELPER_DLL_LOCAL
#elif defined __GNUC__ && (4 <= __GNUC__)
# define OPENRTI_HELPER_DLL_LOCAL  __attribute__ ((visibility("hidden")))
#elif defined __SUNPRO_C && (0x550 <= __SUNPRO_C)
# define OPENRTI_HELPER_DLL_LOCAL  __hidden
#else
# define OPENRTI_HELPER_DLL_LOCAL
#endif