So... I have some problems with my class that is supposed to do something with time... I get an error saying: 22 C:\xxx.cpp `const Time Time::operator-(const Time&, const Time&)' must take either zero or one argument
You wrote a non-member function. However, operator- is a member function. The lefthand side (VR_1) is going to actually be "*this". So your protyotype should be:
const Time operator -(const Time &VR_2)
By the way--I'm not sure why you want the return type to be const.
How is it not a member function, it is inside the class body...
Anyway, if I remove "const Time &VR_1", it will report an error saying something about undeclared stuff.
Btw, I didn't learn anything about " *this " except that it is a pointer (obviously).
And for that const return type, it is just something that I didn't notice while I was typing... Thanks fo that too :P
What I meant was, it was written as if it were not a member function. You were writing a function that takes 2 Time references and returns a third. That is not really how a member function works. A member function would take a Time reference, add it to itself and return the result.
Read this tutorial. It should help. Specifically, read the CVector::operator+ example.
I'm sort of new to c++ too, but I think you may be better served by NOT making the overloaded operator- function a member function. Instead, the way you intend to use the operator- function, it may be best to make it a "friend" of the Time class instead of a member function, and return a Time object. To make this function a friend, you'll need to declare it as such in the public section (without the implementation)
friend Time operator-(const Time& VR_1, const Time& VR_2);
You will have define the friend function outside of the class or in an implementation file