Azam
Azam

Reputation: 797

Macro variable after class keyword

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?

Upvotes: 5

Views: 564

Answers (2)

stinky472
stinky472

Reputation: 6797

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.

Upvotes: 3

Matthew Flaschen
Matthew Flaschen

Reputation: 284786

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)

Upvotes: 5

Related Questions