have a member function that is defined as follows.
1 2 3 4
const Time Time::operator+(const Time &other) {
int hour = (*this).getHour() + other.getHour();
int min = (*this).getMinute() + other.getMinute();
int sec = (*this).getSecond()+ other.getSecond();
When I compile the source, I got
error: Date.cpp:16:12: error: extra qualification ‘Time::’ on member ‘operator+’ [-fpermissive] const Time Time::operator+(const Time &other) ;
this is how Visual Studio say
1 IntelliSense: 'this' may only be used inside a nonstatic member function
and this is how g++ works
In file included from time.cpp:1:0:
Time.h:11:12: error: extra qualification ‘Time::’ on member ‘operator+’ [-fpermissive]
const Time Time::operator+(const Time &other) ;
^
Time.h:19:6: error: extra qualification ‘Time::’ on member ‘get’ [-fpermissive]
void Time::get( );
^
Time.h:20:6: error: extra qualification ‘Time::’ on member ‘display’ [-fpermissive]
void Time::display();
^
class Time
{
public:
Time( int = 0, int = 0 );
const Time operator+(const Time &other);
void setTime( int, int);
void setHour( int );
void setMinute( int );
int getHour() const;
int getMinute() const;
void get(); //declaration, no Time::
void display();
private:
int hour;
int minute;
};
//member function definition outside of class definition
//must say which class it belongs to
void Time::get( )
{
int hour, minute, second;
cout << "Enter hour : " ;
cin >> hour;
cout << endl ;
cout << "Enter minute : " ;
cin >> minute;
cout << endl ;
setTime(hour,minute);
}