Skip to main content
gamedev.net
🔒 Locked

Using operator from another class

Started by Revelation60 Jul 29, 2007 at 5:40 AM 4 replies 550+ views
Original Post
Revelation60
Revelation60
Hi, I'm trying to use the minus operator from my vector class in the plane class, but it doens't recognise the operator.

PLANE::PLANE(CVec3 &p1, CVec3 &p2, CVec3 &p3)
{
	
	normal =  (p2 - p1).Cross(p3 – p1);   --> goes wrong here

How can I fix that?
Currently working on WalledIn
ToohrVyk
ToohrVyk
Well, when something is wrong about operations, you can fix it by correcting the error. Sadly, that's about as insightful an answer can be given the extremely small amount of information you've provided. As a rule of thumb, whenever you enquire on a public forum about a compiler error, make sure you provide the exact full text of the compiler error for everyone to read.

Seriously, there are at least half a dozen reasons why this wouldn't work, including incorrect definition of operations (did you correctly define them?), incorrect definition of cross (do you respect const-correctness, and why is it a member function, anyway?), forgetting to include a header (are all necessary headers included?), namespace issues, file issues, the presence of cast operators combined with any of the above, and so on.

Unless we know the exact error that you get, along with the definition of your operators and the cross function, there are just too many possibilities to list them all.
DaBono
DaBono
Have you #included the header file in which you declare the CVec3-class in the code of your plane class?
If that's not it, what errors do you get, exactly?
Revelation60
Revelation60
I'm sorry I gave too little information, I thought it had to be something straight forward.

class CVec3{public:	// Data	float x, y, z;	inline CVec3 operator- (const CVec3& V2) const		{		return CVec3( x - V2.x,  y - V2.y,  z - V2.z);		}	inline CVec3 operator- ( ) const		{		return CVec3(-x, -y, -z);		}	inline CVec3 Cross( const CVec3 &V2 ) const		{		return CVec3(			y * V2.z  -  z * V2.y,			z * V2.x  -  x * V2.z,			x * V2.y  -  y * V2.x 	);		}...}...PLANE::PLANE(CVec3 &p1, CVec3 &p2, CVec3 &p3){		normal =  (p2 - p1).Cross(p3 – p1);..}


Error C2146: syntax error : missing ')' before identifier '–'


edit:

this does work:

CVec3 test =  (p2 - p1);	CVec3 test2 =  (p3 - p1);		normal =  test.Cross(test2);
Currently working on WalledIn
ToohrVyk
ToohrVyk
Funny.

When you wrote Cross(p3 – p1);, the minus character is not actually a minus character, but something that just looks like one in your font. From the looks of it, it's an endash!

For comparison, your "minus", a real C++ minus, an endash, an emdash, and a mathematical minus:
– - – — −

Delete it and type it again. And don't copy-paste code from Microsoft Word [wink]
Revelation60
Revelation60
Haha, that explains everyting :)

It was a pdf btw ;)
Currently working on WalledIn

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.