Jump to content
  • Advertisement
Sign in to follow this  
eGamer

namespace problem

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

well well well... consider this problem:
// header a.h
#include "b.h"
namespace A
{
  struct st_a
  {
     int a;
     B::st_b2 b;
  };

  struct st_a2
  { int x;
  };
}

// header b.h
#include "a.h"
namespace B
{
  struct st_b
  {
     int b;
     A::st_a2 a;
  };
struct st_b2
  {
     int b;
  };
};
the two namespaces need each other how could we solve the problem does anyone can help me? edit: added code tags -SiCrane

Share this post


Link to post
Share on other sites
Advertisement
Just break up your files into smaller chunks. Make an a1.h, an a2.h, a b1.h and a b2.h. b1.h only would need a2.h and a1.h only needs b2.h.

Share this post


Link to post
Share on other sites
Actually, the problem is not specific to namespaces. The solution is for the struct to contain a reference to an instance of the other struct. That way you can use a forward declaration instead of including the header file. For example:
 // header a.h

namespace B { struct st_b2; }

namespace A
{
struct st_a
{
int a;
B::st_b2 * b;
};

struct st_a2
{
int x;
};
}

// header b.h

namespace A { struct st_a2; }

namespace B
{
struct st_b
{
int b;
A::st_a2 * a;
};
struct st_b2
{
int b;
};
}

Share this post


Link to post
Share on other sites
that's exactly what i wanted : declaring namespaces...? which are "in concept" different from declaring namespaces mentioned in any MSDN or c++ book ?

thanks a lot i solved the problem with this, now i can get use of the power of
namespaces for managing large projects.

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!