<分区>
我想创建一个类似这样的类:
class MyTime {
public:
int seconds;
int useconds;
/*** functions ***/
}
但具有以下行为:
MyTime now;
double current_time = now; // returns double representing seconds
有没有一种方法可以做到这一点而不必定义 asDoubleSeconds()
函数?我可以通过某种方式重载赋值运算符来改变行为吗?
如果没有,有没有办法做这样的事情:
double current_time = double(now);