Macro variable after keyword

I found this in the Ogre Framework

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

and he determines how it is

 #define _OgreSampleClassExport 

Why do we want to have this variable?

+4
source share
2 answers

Presumably, for such classes, a special classifier, such as __declspec(dllexport) , can be added by changing (or conditionally defining) the definition:

 #define _OgreSampleClassExport __declspec(dllexport) 
+5
source

This is for future exports. Ogre may just be a statically linked library for now, but if the authors ever decide to support dynamically linked libraries (the so-called shared libraries on some platforms), they will need to write code like:

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

... and this is only for MSVC. Usually they had to make an effort to do this with Sample_Character and all the other classes that they provide through their library. Creating a separate macro, which will be defined later, is much simpler, since it needs to be done in only one place.

+2
source

Source: https://habr.com/ru/post/1314283/


All Articles