Hi all!
I just have a quick question about the execution of a copy constructor. This is the code i'm testing my work with as I'm busy learning for a test.
Class file:
Clock :: Clock (int h, int m, int s)
{
hr = h;
min = m;
sec = s;
cout << " Default constructor " << endl ;
}
Clock :: Clock ( const Clock & c)
{
hr = c.hr;
min = c.min ;
sec = c.sec ;
cout << " Copy constructor " << endl ;
}
Clock Clock :: LunchTime () {
hr = 12;
min = 0;
sec = 0;
return * this ;
}
bool Clock :: equal ( const Clock c)
{
return hr == c.hr && min == c.min && sec == c.sec ;
}
Then in the main :
int main () {
Clock c1 (12 ,0 ,0);
Clock c2;
c2. LunchTime ();
if (c1. equal (c2))
cout << " Times are equal " << endl ;
}
My question is why is it that the c2.LunchTime() triggers the copy constructor? And with the next line if (c1. equal (c2)) it also calls the copy constructor?
Any help will be appreciated!