Sign in to follow this  
paic

namespace and enum

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 <iostream>
#include "SceneGraphEditor.h"
using namespace std;

int main()
{
Test t;

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


But, I'm using VS.NET 2003...

Share this post


Link to post
Share on other sites
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_'..

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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