Jump to content
  • Advertisement
Sign in to follow this  
Mulligan

namespace question

This topic is 5067 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

I'm going through tons of code right now, adding namespaces to stop name clashing that is popping up, but dont know if I should include headers within the namespace. Example: file.h
namespace Game
{
    #include <windows.h>

    class foo
    {
    ...
    };
}

OR

#include <windows.h>

namespace Game
{
    class foo
    {
    ...
    };
}

Does it matter, or is one more correct?

Share this post


Link to post
Share on other sites
Advertisement
I don't think it should matter if all your namespaces are in different header files. But I would just put the includes at the top of your file, outside the namespace.

I use the Irrlicht engine and it makes use of namespaces heavily, and I don't think any header files are included inside the namespaces themselves.

Share this post


Link to post
Share on other sites
If you put windows.h in the Game namespace then all the functions in there will be in the namespace. It will have the effect of modifying the declarations of the functions as they'll now be things like Game::GetDeviceCaps instead of ::GetDeviceCaps. The libraries you are linking against will have ::GetDeviceCaps in them.

On the whole it's not good practice to wrap other peoples headers in a namespace, although there may be (dubious) reasons why you would want to do it with your own files.

Pete

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!