   [solved] namespaces trouble
  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]
  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   ;  Ok, thx a lot for the explanation, now I understand namespace a little better (and it works) ^^   