Sign in to follow this  

header inside a namespace C++

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

This topic is 3300 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.

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