即使我没有构造函数,如何将对象用作参数?
#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;
}
我以为我需要这样的构造函数用于T2,但它仍然有效。为什么呢?
Time(Time t) {
//maybe do something
return t;
}