Jump to content
  • Advertisement
Sign in to follow this  
Tengato

Need help understanding odd C++ semantic

This topic is 2009 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?

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

_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:

 

204 #if OGRE_PLATFORM == OGRE_PLATFORM_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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!