Jump to content
  • Advertisement
Sign in to follow this  
paic

[solved] namespaces trouble

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

Hi, I've got another problem with namespaces. Here is what I want to do :
//---------------------------------
// NodeFactory.h :

namespace SceneGraphEditor {

class CNodeFactory
{
   // ...
}

}


//---------------------------------
// NodeFactory.cpp :

#include "NodeFactory.h"

using namespace SceneGraphEditor;

CNodeFactory::CNodeFactory(void)
{
   // ...
}

// ...


//---------------------------------
// CameraNode.cpp :

namespace
{
   #include "NodeFactory.h"
   using namespace SceneGraphEditor;

   ISceneGraphNode * CreateCamera(void)
   {
      return((ISceneGraphNode *)new CCameraModelView);
   }

   bool registered = CNodeFactory::GetInstance()->Register("camera", CreateCamera);
}


Ok, the problem is in CameraNode.cpp. When I compile, there's no problem. But when linking, I've got unresolved symbol "anonymous namespace'::SceneGraphEditor::CNodeFactory::GetInstance(void)" and a few other. Is it possible to use something from the namespace SceneGraphEdtior inside an other namespace ?? Thx for any help. [Edited by - paic on June 13, 2006 9:59:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
You have two problems. The first is that you have a #include directive inside a namespace (the anonymous namespace). This means that everything included via that #include will be nested within that namespace. Move your #include directive out of the namespace. The second problem is that using namespace only affects usage of variables, not definitions. This means that in NodeFactory.h you are declaring SceneGraphEditor::CNodeFactory but in NodeFactory.cpp you are trying to define members of a class ::CNodeFactory. You either need to wrap the cpp file in the namespace just like NodeFactory.h or else qualify each member with the namespace as well (i.e. SceneGraphEditor::CNodeFactory::CNodeFactory).

So you want something like:
// NodeFactory.h :

namespace SceneGraphEditor {

class CNodeFactory
{
// ...
};

}

// NodeFactory.cpp :

#include "NodeFactory.h"

namespace SceneGraphEditor {

CNodeFactory::CNodeFactory(void)
{
// ...
}

// ...

}

// CameraNode.cpp :

#include "NodeFactory.h"

namespace
{
using namespace SceneGraphEditor;

ISceneGraphNode * CreateCamera(void)
{
return((ISceneGraphNode *)new CCameraModelView);
}

bool registered = CNodeFactory::GetInstance()->Register("camera", CreateCamera);
}

Σnigma

Share this post


Link to post
Share on other sites
Ok, thx a lot for the explanation, now I understand namespace a little better (and it works) ^^

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!