I've created a time class, which I would like to add the operator+ to.
I'm getting an error though:
1 2 3 4 5
$ make
g++ -c -Wall -std=gnu++11 time.cpp
In file included from time.cpp:2:0:
time.h:15:45: error: ‘Time& Time::operator+(Time&, const Time&)’ must take either zero or one argument
Time& operator+(Time & s, const Time & t)
The files are as follows:
time.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef TIME0_H_
#define TIME0_H_
class Time {
private:
int hours;
int minutes;
public:
Time();
Time(int h, int m = 0);
void AddMin(int m);
void AddHr(int h);
void Reset(int h = 0, int m = 0);
Time& operator+(Time & s, const Time & t)
void Show() const;
};
#endif
Search for C++ Primer (5th ed.) by Stephen Prata - Chapter 11 - Time on Our Hands: Developing an Operator Overloading Example - is just the thing you might be looking for