Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MENTAL

Is this legal?

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

1) Can i use "using namespace xxx" when writing function bodies for "namespace xxx", for example:
namespace XXX
{
    void SomeFunc ();
};

using namespace XXX;

void SomeFunc ()
{
    printf ("Hello!");
}

2) If i have some nested namespaces defined in multiple files, do i have to include the file containing the namespace definition to use the namespace?
// In Foo.h

namespace BigSpace
{
    namespace Foo
    {
        void FooFunc ();
    }
}

// In Bar.h

namespace BigSpace
{
    namespace Bar
    {
        void BarFunc ();
    }
}

// In Bar.cpp

#include "Bar.h"

void BigSpace::Bar::BarFunc ()
{
    BigSpace::Foo:FooFunc ();
}

would that run, or do i have to include "Foo.h". I''m hopeing so, because that way I can keep parts of the namespace hidden from other code modules unless they specifically need them. thanks

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by MENTAL
1) Can i use "using namespace xxx" when writing function bodies for "namespace xxx", for example:

No.

Try this:

namespace XXX
{
void SomeFunc();
}

namespace XXX
{
void SomeFunc() { ... }
}

// OR


void XXX::SomeFunc() { ... }


quote:
2)


Of course you Have to include Foo.h. Before Foo.h is included in Bar.cpp, the compiler doesn''t even know that BigSpace::Foo::FooFunc() exists; it''s never heard of it.



How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
thanks for the reply. i thought that might be the case with 2, but the whole "namespaces don''t need to be defined in a single file" bit threw me a bit .

Share this post


Link to post
Share on other sites

  • 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!