Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange class declaration

Tags:

c++

class

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

class Q_CORE_EXPORT QRect {
};

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

like image 407
There is nothing we can do Avatar asked Jun 30 '10 11:06

There is nothing we can do


2 Answers

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

A snippet from that source:

#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

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

like image 90
Mark Rushakoff Avatar answered Sep 28 '22 10:09

Mark Rushakoff


Q_CORE_EXPORT isn't an identifier. It's a platform-dependent macro, and it's used to signal a class that's intended to be used across library boundaries. In particular, it's defined by the Qt core library and used by other Qt libraries.

like image 43
MSalters Avatar answered Sep 28 '22 08:09

MSalters