Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro variable after class keyword

Tags:

c++

macros

I found this in Ogre Framework

class _OgreSampleClassExport Sample_Character : public SdkSample {
...
...

and it's define like this

#define _OgreSampleClassExport

Why we want to have this macro variable?

like image 782
Azam Avatar asked Feb 26 '23 18:02

Azam


2 Answers

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)
like image 118
Matthew Flaschen Avatar answered Mar 07 '23 19:03

Matthew Flaschen


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.

like image 36
stinky472 Avatar answered Mar 07 '23 19:03

stinky472