Error C2373 VS2008, doesn't make sense :(

Started by
0 comments, last by mikfig 14 years, 1 month ago
Here is my source code: header file:

class Variant
{
public:

	typedef enum
	{
		INTEGER,
		FLOAT,
		BOOL,
		STRING,
		VECTOR2,
		VECTOR3,
		VECTOR4,
		MATRIX3X3,
		MATRIX4X4,
		NULL_VARIANT
	} TYPE;

	Variant()
		: m_VariantType(NULL_VARIANT)
	{}

	...

	float   operator[](int a_iIndex) const;
	...

private:
	...
};

implementation file:

...
float Variant::operator [](int a_iIndex) const
{
	if(a_iIndex > 15) // invalid index
		assert(false);
	else if(a_iIndex > 8) // can't be a matrix3x3 or vector
		assert(m_VariantType == MATRIX4X4);
	else if(a_iIndex > 3) // can't be a vector
		assert(m_VariantType == MATRIX3X3 ||
			   m_VariantType == MATRIX4X4);
	else if(a_iIndex > 2) // can't be a vector3 or vector 2
		assert(m_VariantType == VECTOR4	  ||
			   m_VariantType == MATRIX3X3 ||
			   m_VariantType == MATRIX4X4);
	else if(a_iIndex > 1) // can't be a vector2
		assert(m_VariantType == VECTOR3   ||
			   m_VariantType == VECTOR4	  ||
			   m_VariantType == MATRIX3X3 ||
			   m_VariantType == MATRIX4X4);
	else if(a_iIndex < 0) // invalid index
		assert(false);

	return m_FloatArray[a_iIndex];
}
...

Visual Studio 2008 is giving me error C2373: 'Variant::operator []' : redefinition; different type modifiers So it seems that if operator[] is defined twice then i would be able to comment out the definition for Variant::operator[] in the implementation file and I wouldn't get any linking errors if I used that function in another file. However, that is not the case. I researched this error and it seems to be a bug with Visual Studio 2008, but I'm really not sure. I installed SP1, hoping to have that "bug" be fixed. But the error still occurs. It seems that a lot of people had this issue when migrating code from previous version of VS to 2008, but I started this project in 2008. Does anyone see this cause of this error? Thanks, mikfig
"WARNING: Excessive exposure to politicians and other bureaucrats has been linked to aggressive behavior." - Henk Hopla
Advertisement
Uhhh! Now I feel like such an idiot. The problem was simply this:

I declared a function before the operator like this:

TYPE GetVariantType() { return m_VariantType; } const

however it obviously should have been declared like this:

TYPE GetVariantType() const { return m_VariantType; }


Stupid! Stupid! Stupid! :P lol

Thanks anyways,
mikfig
"WARNING: Excessive exposure to politicians and other bureaucrats has been linked to aggressive behavior." - Henk Hopla

This topic is closed to new replies.

Advertisement