Jump to content
  • Advertisement
Sign in to follow this  
CmpDev

header inside a namespace C++

This topic is 3519 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 can not seem to find the answer in the standard, maybe someone here knows the answer or the part I should look at. What is the defined behaviour of including a header inside a namespace? I know that everything is in a namespace, somtimes just the global namespace, but if I had a header which has a function foo in global and I included this header inside a namespace bar. Would the function be accessible by bar::foo or just foo inside this translation unit?

Share this post


Link to post
Share on other sites
Advertisement
First off, don't do this, it's extremely error prone. Secondly, what happens depends on a number of factors. If the header has include guards, and already has been included in the translation unit, then nothing happens. If the header doesn't have include guards or hasn't already been included, then the functions would be placed nested inside that namespace. And if it gets included differently in two different translation units, you're going to have a good chance of getting a violation of the one definition rule.

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!