Skip to main content
gamedev.net
🔒 Locked

namespace and enum

Started by paic Jun 6, 2006 at 3:55 AM 5 replies 900+ views
Original Post
paic
paic
Hi, I started using namespaces for my project, and I have some troubles with enums. In a header, I have something like :

namespace SceneGraphEditor {

enum eResourceType
{
   SGE_RESOURCE_UNDEFINED = 0,
   SGE_RESOURCE_TEXTURE,
   SGE_RESOURCE_VOLUMETEXTURE
   // ...
};

// ...

}
and in a .cpp I want to do something like :

using namespace SceneGraphEditor;

CDXVolumeTexture::CDXVolumeTexture(void)
{
   m_Type = SGE_RESOURCE_VOLUMETEXTURE;
   // ...
}
But it doesn't work : "error C2065: 'SGE_RESOURCE_VOLUMETEXTURE' : undeclared identifier" Is there something wrong in my code ? If it helps : I'm using VS2005 with /clr [Edited by - paic on June 6, 2006 7:13:30 AM]
stephanus
stephanus
Hmm.. Seems working for me...

FILE: SceneGraphEditor.h
////////////////////////////////////////////////////////////
namespace SceneGraphEditor
{
enum eResourceType
{
SGE_RESOURCE_UNDEFINED = 0,
SGE_RESOURCE_TEXTURE,
SGE_RESOURCE_VOLUMETEXTURE
};
};

class Test
{
public:
SceneGraphEditor::eResourceType m_Type;
Test();
~Test();
};
/////////////////////////////////////////////////////////////

FILE:SceneGraphEditor.cpp
/////////////////////////////////////////////////////////////
#include "SceneGraphEditor.h"
using namespace SceneGraphEditor;

Test::Test()
{
m_Type = SGE_RESOURCE_UNDEFINED;
}

Test::~Test()
{
}
/////////////////////////////////////////////////////////////

FILE:test.cpp
/////////////////////////////////////////////////////////////
#include
#include "SceneGraphEditor.h"
using namespace std;

int main()
{
Test t;

return 0;
}
/////////////////////////////////////////////////////////////


But, I'm using VS.NET 2003...
StephanusSIWare, Inchttp://graphics.harvestsoft.net
Taha Ansari
Taha Ansari
Declaration of namespace and enum appears to be alright. But in the part where you're getting error, the error that you've posted is:

"error C2065: 'AM_RESOURCE_VOLUMETEXTURE' : undeclared identifier"

whereas, I cannot see that enumeration defined in the header, except for "SGE_RESOURCE_VOLUMETEXTURE". Are you sure you're using 'AM_RESOURCE_VOLUMETEXTURE' defined enum somewhere else? If you dont have that defined, then thats most likely the cause of the problem: 'AM_' being used instead of 'SGE_'..
paic
paic
Whoops, I made a typo in the subject.
In my code, there is no such typo (it was copied / pasted from another project made with VS2003 and which worked. And I added the namespaces when porting to VS2005)
paic
paic
Ok, found the problem (and learnt something)

my files are like that :
// IResource.h :namespace SGE {enum eResourceType{   TEXTURE = 0,   VERTEXBUFFER   // ...};class IResource{   eResourceType m_Type;   // ...};}// Texture.h :namespace SGE {#include "Resouce.h"class CTexture : public SGE::IResource{   // ...};}// Texture .cpp :#include "Texture.h"using namespace SGE;CTexture::CTexture{   m_Type = TEXTURE;}


The problem comes from the #include "Resource.h" which is located after the beginning of the namespace block. If I move it before the beginning of the namespace block, then it works correctly.
Zahlman
Zahlman
Remember, #include is just an automated text copy-and-paste hack. So if you put that directive inside the namespace brackets, the included function declarations etc. are declared as namespace members.
Palidine
Palidine
You don't need:

using namespace SGE;

instead you can access your enums by scoping them:

CTexture::CTexture{   m_Type = SGE::TEXTURE;}


-me

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.