Jump to content
  • Advertisement
Sign in to follow this  

Need help understanding odd C++ semantic

This topic is 2090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a basic understanding of C++, but when I examine real-world code I still encounter lots of confusing bits and pieces.  For example, this class declaration from the Ogre 3D source:


class _OgreExport Root : public Singleton<Root>




What is _OgreExport?



Share this post

Link to post
Share on other sites

_OgreExport is probably some weird #define the Ogre team made.



Yep, it is.  You can see it in action here.  That is where they defined it.



Basically in C++ there is something called the preprocessor, it's what deals with all the lines that start with # like #include or #define.  At the simplest level, it replaces the Macro with the defined value.


In this case, it's to handle the various platforms.  For example, for Android:


205 # define _OgreExport
It has no value.  Meaning that when compiled for Android, the value _OgreExport will be replaced with an empty value.
While later on down, you can see if Ogre is being compiled as a DLL, it gets a different value:
156 # else
157 # if defined( OGRE_NONCLIENT_BUILD )
158 # define _OgreExport __declspec( dllexport )
159 # else
In this case, your code to the compiler will appear as:
class __declspec( dllexport) Root: public Sin.....
Make sense?

Share this post

Link to post
Share on other sites

And __declspec( dllexport) is a non-standard (i.e. compiler specific) feature in Microsoft's compilers. There's some information here on it.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!