How is it possible to use an object as a parameter even though I don't have a constructor for it?
#include <iostream>
#include <string>
using namespace std;
class Time
{
private: int hh, mm, ss;
public: static Time sec_to_Time (unsigned int sec)
{
Time U;
U.hh = sec / 3600;
sec -= U.hh * 3600;
U.mm = sec / 60;
sec -= U.mm * 60;
U.ss = sec;
return (U);
}
};
int main()
{
Time T1 = Time::sec_to_Time(60); //I understand this code,
Time T2(Time::sec_to_Time(60)); //but why does this work?
return 0;
}
I thought I'd need a constructor like this for T2, but it's still working. Why?
Time(Time t) {
//maybe do something
return t;
}