Advertisement Jump to content
Sign in to follow this  
dyerseve

Nested classes

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

Say I have a class with another class nexted inside it. Suppose the class has a named enum:
class CMesh {
protected:
	enum PrimitiveType {
		PrimitiveType_PointList=1,
		PrimitiveType_LineList=2,
		PrimitiveType_LineStrip=3,
		PrimitiveType_TriangeList = 4,
		PrimitiveType_TriangeStrip = 5,
		PrimitiveType_TriangeFan = 6
	};
	class CBatch {
	public:
		void foo();

		PrimitiveType m_Type; //No error here
		//Other variables
	};

Now say in another file I want to define foo(). The problem is that I can't access the PrimitiveType enum.
void CMesh::CBatch::foo() {
	switch (m_Type) {
	case 4:
		//This works fine
	case CMesh::PrimitiveList_TriangleList:
		//error C2065: 'PrimitiveList_TriangleList' : undeclared identifier
	case PrimitiveType::PrimitiveList_TriangleStrip:
		//error C2039: 'PrimitiveList_TriangleStrip' : is not a member of 'PrimitiveType'
	case CMesh::PrimitiveList_TriangleFan:
		//error C2039: 'PrimitiveList_TriangleFan' : is not a member of 'CMesh'
	case CMesh::PrimitiveType::PrimitiveList_TriangleFan:
		//error C2039: 'PrimitiveList_TriangleFan' : is not a member of 'PrimitiveType'
	case ::PrimitiveList_TriangleFan:
		//error C2051: case expression not constant
	case ::PrimitiveType::PrimitiveList_TriangleFan:
		//error C2051: case expression not constant
	}
}

plus a bunch of resulting undeclared identifier errors and such. Can someone please tell me the right way to access the enums?

Share this post


Link to post
Share on other sites
Advertisement
err, scratch that whole post.

Somehow PrimitiveType became PrimitiveList and I spelled Triangle wrong... that was the problem. Mesh::PrimitiveType_Triangle works now.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!