//Hi all,can you please explain why using this-> in this code is optional,that is the purpose?
//Code can work with not this-> too.
CTime_24 operator+(int seconds);
CTime_24 CTime_24 :: operator+(int seconds)
{
CTime_24 temp;
temp.m_Seconds = this->m_Seconds + seconds;
temp.m_Minutes = this->m_Minutes + temp.m_Seconds / 60;
temp.m_Seconds %= 60;
temp.m_Hours = this -> m_Hours + temp.m_Minutes / 60;
temp.m_Minutes %= 60;
temp.m_Hours %= 24;
return temp;
}
int main()
{
CTime_24 time2(6, 20, 59);
time2.GetTime(hour, minute, second);
cout << "time2=" << hour << " : " << minute << " : " << second << endl;
////OVERLOADED OPERATOR CALL///////
time2 = time1 + 45;
time2.GetTime(hour, minute, second);
cout << "time2 =" << hour << " : " << minute << " : " << second << endl;
}
aluhnev 0 Junior Poster in Training
Moschops 683 Practically a Master Poster Featured Poster
aluhnev 0 Junior Poster in Training
NathanOliver 429 Veteran Poster Featured Poster
aluhnev 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.