I'm trying to write some code that creates a class with the privates hours and minutes. Now I'm trying to create a new class from a integer minus a other class.
class Foo
{
Public:
Foo(int u, int m);
Foo(int m);
int operator-(const Foo& other);
friend Foo operator-(int lhs, const Foo& rhs);
Private:
int minute, hour;
};
Foo::Foo(int u, int m): hour(u), minute(m){}
Foo::Foo(int m): hour(0), minute(m){}
int Foo::operator-(const Foo& other)
{
int x;
x = (60*(uur-other.uur));
x += (min - other.min);
return x;
}
main()
{
Foo t1(2,10);
const Foo kw(15);
Foo t2(t1 -kw);
Foo t3(2,10);
Foo t4(132 -t3);
}
Now I can't get T4 to contain only 2 minutes (132 - ((60 * 2) -10)) Does anyone know how to solve this? I get the error: error: no match for 'operator-' (operand types are 'int' and 'Foo')
void operator-(int x, const Foo& other);
When I include this function i get the error error: 'void Foo::operator-(int, const Foo&)' must take either zero or one argument. Got it working with the following code:
Foo operator-(int lhs, const Foo& rhs)
{
int y;
y = lhs - rhs.min;
y -= (60 * rhs.uur);
return y;
}