Jump to content
  • Advertisement
Sign in to follow this  
paic

namespace and enum

This topic is 4397 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 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
Advertisement
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
You don't need:

using namespace SGE;

instead you can access your enums by scoping them:


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


-me

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!