开发者

Macro variable after class keyword

开发者 https://www.devze.com 2023-01-05 08:40 出处:网络
I found this in Ogre Framework class _OgreSampleClassExport Sample_Character : p开发者_Go百科ublic SdkSample {

I found this in Ogre Framework

class _OgreSampleClassExport Sample_Character : p开发者_Go百科ublic SdkSample {
...
...

and it's define like this

#define _OgreSampleClassExport

Why we want to have this macro variable?


Presumably so a special qualifier, such as __declspec(dllexport), could be added to such classes by modifying (or conditionally defining) the define:

#define _OgreSampleClassExport __declspec(dllexport)


It's to allow for future exports. Ogre may just strictly be a statically linked library at the moment, but if the authors ever decide to support dynamically-linked libraries (aka shared libraries on some platforms), they will need to write code like:

class
#ifdef EXPORTING
    __declspec(dllexport)
#else
    __declspec(dllimport)
#endif
Sample_Character [...]

... and that's just for MSVC. Normally they'd have to go through the effort to do this to Sample_Character and all other classes they provide through their library. Making a single macro to be defined later is much easier as they'll only need to do this in one place.

0

精彩评论

暂无评论...
验证码 换一张
取 消