奇怪的类声明 [英] Strange class declaration

查看:128
本文介绍了奇怪的类声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Qt的qrect.h中我发现类声明开始如下:

In Qt's qrect.h I found class declaration starting like this:

class Q_CORE_EXPORT QRect {
};

正如你可以看到class关键字后面有两个标识符。我如何理解这个?

谢谢。

As you can see there are two identifiers after class keyword. How shall I understand this?
Thank you.

推荐答案

Q_CORE_EXPORT 一个可扩展为不同值的宏

Q_CORE_EXPORT is a macro that gets expanded to different values depending on the context in which it's compiled.

来自该来源的片段:

#ifndef Q_DECL_EXPORT
#  ifdef Q_OS_WIN
#    define Q_DECL_EXPORT __declspec(dllexport)
#  elif defined(QT_VISIBILITY_AVAILABLE)
#    define Q_DECL_EXPORT __attribute__((visibility("default")))
#  endif
#  ifndef Q_DECL_EXPORT
#    define Q_DECL_EXPORT
#  endif
#endif
#ifndef Q_DECL_IMPORT
#  ifdef Q_OS_WIN
#    define Q_DECL_IMPORT __declspec(dllimport)
#  else
#    define Q_DECL_IMPORT
#  endif
#endif

// ...

#    if defined(QT_BUILD_CORE_LIB)
#      define Q_CORE_EXPORT Q_DECL_EXPORT
#    else
#      define Q_CORE_EXPORT Q_DECL_IMPORT
#    endif

这些值( __ declspec(dllexport) __attribute __((visibility(default)))等)是编译器特定的属性,指示函数在动态库中的可见性。

Those values (__declspec(dllexport), __attribute__((visibility("default"))), etc.) are compiler-specific attributes indicating visibility of functions in dynamic libraries.

这篇关于奇怪的类声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆