Sign in to follow this  

Need help understanding odd C++ semantic

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this