I did not get a compiler warning. Vector.getZ() also returns a float.
That's because an explicit conversion is happening.
THe Floating Brain wrote:
Agreed that I should probably put my magnitude calculation into a function/method so it can return the magnitude. The reason for not sqrt'ing it is so I can use the if statement to make sure my number does not come out N.A.N.
1>------ Build started: Project: Vector Scan Area, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>c:\users\aperson\documents\visual studio 2008\projects\vector scan area\vector scan area\vector calculator.h(24) : error C2804: binary 'operator ==' has too many parameters
1>c:\users\aperson\documents\visual studio 2008\projects\vector scan area\vector scan area\vector calculator.h(24) : error C2333: 'Math::Vector::Vector_Calculator::operator ==' : error in function declaration; skipping function body
1>c:\users\aperson\documents\visual studio 2008\projects\vector scan area\vector scan area\vector calculator.h(36) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Containers::Base::XYZ' (or there is no acceptable conversion)
1> c:\program files\microsoft sdks\windows\v6.0a\include\guiddef.h(192): could be 'int operator ==(const GUID &,const GUID &)'
1> while trying to match the argument list '(Containers::Base::XYZ, int)'
1>Build log was saved at "file://c:\Users\aperson\Documents\Visual Studio 2008\Projects\Vector Scan Area\Vector Scan Area\Debug\BuildLog.htm"
1>Vector Scan Area - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I feel like such a noob
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
the error is saying you're providing too many arguments. As it is, you'd have to say it Vec1 == Vec2, 3. And that's just plain wrong. r, the const int, is supposed to be provided in the source file, not as a parameter to the operator.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
//Modified to fit my program. I did test this with a struct instead of a class I get the same result.//
inline bool operator==( const Containers::Base::XYZ &lhs, const int r ) {
return ((lhs.getX() - r) < FLT_EPSILON) && ((lhs.getY() - r) < FLT_EPSILON) && ((lhs.getZ() - r) < FLT_EPSILON);
}
Containers::Base::XYZ Vector_Calculation( Containers::Base::XYZ Goto, Containers::Base::XYZ Position, float Speed )
{
...
if( Vector == 0 )
return Vector;
...
}
Or are you saying this should be declared outside the class "Vector_Calculator" in the source file?
???
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
Yes. Define the method outside the class, inside the same namespace. Preferably within the same source file. The reason for this is you can completely define the == operator in terms of vectors public interface.
My experience tells me, if you can declare a function in terms of its pre-existing public interface, and it makes sense to do so, then do it. There is no reason to lower encapsulation by making the == operator a member function of the vector class.