troubleshooting Question

can an enumerant mask (obscure) a type in C++ ??

Avatar of jochemspek
jochemspekFlag for Netherlands asked on
ProgrammingC++
7 Comments1 Solution314 ViewsLast Modified:
Hi there, I just learnt the hard way that the following code won't compile and give the error (in MSVC)

error C2146: syntax error : missing ';' before identifier 'm_naabb'

#include "NAABB.h"

class RenderNode {
	public:
		/**
			@enum RenderComponents
			bitmask that determines which components are rendered
		*/
		typedef unsigned int ComponentMask;
		enum RenderComponents {
			NONE	= 0x0000,
			AABB	= 0x0001,
			NAABB	= 0x0002,
			AXES	= 0x0004,
			NORMALS	= 0x0008,
			ALL		= 0xFFFF
		};
                ComponentMask m_components;
		NAABB	          m_naabb;
};

(assuming all #included files are correct and there is a class named NAABB, for 'non-aligned-bounding-box'.
the intent of the enum is to be able to selectively render components of a node in a scenegraph where it would
be convenient if the components are named after the types to be rendered - ie to render member m_naabb
of type NAABB by masking in the NAABB enumerant)

Apparently this is because the NAABB in the enum RenderComponents 'obscures' the actual NAABB type,
because if I move the line NAABB m_naabb; to above the enum declaration, all is fine. I've never encountered
this before, and I don't quite understand why the compiler can't resolve this. Could an expert explain this to me ?

Thanks,

Jochem van der Spek
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros