Sign in to follow this  

'Class' uses 'class' which is already being defined... you can't be serious?!

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

I have a managed c++ class...
	public ref class MQuadTree
	{
	private:
		NW::QuadTree* m_quadTree;
	public:
		MQuadTree(MQuadTree ^in_parent, Vector2 in_min, Vector2 in_max) {m_quadTree=new NW::QuadTree((NW::QuadTree*)in_parent->GetUnmanagedPtr().ToPointer();, NW::Vector2(in_min.x, in_min.y), NW::Vector2(in_max.x, in_max.y));}
		~MQuadTree() {delete m_quadTree;}
		IntPtr GetUnmanagedPtr() {return IntPtr(m_quadTree);}
	}

But when compiling I get the compiler error... d:\documents and settings\rprice\my documents\visual studio 2005\projects\terraformer4\mnw\mquadtree.h(21) : error C2460: 'MNW::MQuadTree::MQuadTree' : uses 'MNW::MQuadTree', which is being defined You can't be serious? I must be able to use a pointer/handle to an object of the same type for a parent/child relationship. What am I doing wrong here? Thanks Rael

Share this post


Link to post
Share on other sites
Ugh, god... this compiler is freakin' crazy. It was the definition for Vector2 that was missing, yet it was complaining about a circular reference to the first parameter.

WTH, Microsoft!?

Share this post


Link to post
Share on other sites
That's a valid error. You can't create a new object in the constructor of that object type (without having any stopping case, but still, that's bad design); it will create a new object, call its constructor, create a new object, etc. and go on for infinity. Are you sure you fixed it?

Share this post


Link to post
Share on other sites
Wow, calm down first off =).

Second, errors in headers always cause really messed up messages. The error they give you is correct in regard to what they are parsing and how class names that the compiler doesn't know are classes are being handled. What do you expect from them? "Missing class declaration for Vector2"? How do they know it is a class? How do they know it isn't a function name, or some local variable? They don't even know it is supposed to be a type. Don't blame Microsoft because you wrote some incorrect code and their parser interpreted the (incorrect) code in some strange way.

Share this post


Link to post
Share on other sites
Quote:
Original post by okonomiyaki
That's a valid error. You can't create a new object in the constructor of that object type (without having any stopping case, but still, that's bad design); it will create a new object, call its constructor, create a new object, etc. and go on for infinity. Are you sure you fixed it?

I wasn't trying to pass an object, the ^ qualifier passes a handle to a managed object. Kind of like passing a pointer in regular C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dranith
Wow, calm down first off =).

Second, errors in headers always cause really messed up messages. The error they give you is correct in regard to what they are parsing and how class names that the compiler doesn't know are classes are being handled. What do you expect from them? "Missing class declaration for Vector2"? How do they know it is a class? How do they know it isn't a function name, or some local variable? They don't even know it is supposed to be a type. Don't blame Microsoft because you wrote some incorrect code and their parser interpreted the (incorrect) code in some strange way.

Ha, yes sorry... my frustration got the better of me there for a moment. :D

I guess I didn't expect errors for a parameter that it should be able to parse successfully before the errors for the parameters that I agree with you it shouldn't. It is perfectly reasonable to pass a handle to the same class you are defining as a parameter to a function.

Share this post


Link to post
Share on other sites
Quote:
Original post by Raeldor
Quote:
Original post by okonomiyaki
That's a valid error. You can't create a new object in the constructor of that object type (without having any stopping case, but still, that's bad design); it will create a new object, call its constructor, create a new object, etc. and go on for infinity. Are you sure you fixed it?

I wasn't trying to pass an object, the ^ qualifier passes a handle to a managed object. Kind of like passing a pointer in regular C++.


I think he was referring to the new-expression within the constructor, not the paramater. But that new-expression seems to be for a different type anyway (new NW::QuadTree, when the class being defined is MQuadTree).

*shrugs*

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Quote:
Original post by Raeldor
Quote:
Original post by okonomiyaki
That's a valid error. You can't create a new object in the constructor of that object type (without having any stopping case, but still, that's bad design); it will create a new object, call its constructor, create a new object, etc. and go on for infinity. Are you sure you fixed it?

I wasn't trying to pass an object, the ^ qualifier passes a handle to a managed object. Kind of like passing a pointer in regular C++.


I think he was referring to the new-expression within the constructor, not the paramater. But that new-expression seems to be for a different type anyway (new NW::QuadTree, when the class being defined is MQuadTree).

*shrugs*


Yeah, I was, and I was assuming QuadTree inherited from MQuadTree because it looked like in_parent was being cast to a QuadTree. Now I see that MQuadTree stands for ManagedQuadTree, and in_parent->GetUnmanagedPtr() must return its QuadTree brother. Why the cast to QuadTree* though? I guess it's that's just how the interface to unmanaged objects works- it probably just returns a void pointer or something.

Share this post


Link to post
Share on other sites
You are right on all counts. MQuadTree is the managed version, and I need to cast because IntPtr returns a void pointer. This still smells of a compiler bug to me... maybe I'll run it up on the MSDN forums and see what they make of it.

Thanks :)

Share this post


Link to post
Share on other sites

This topic is 4069 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.

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