Sign in to follow this  

[solved] namespaces trouble

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

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