How do I make a class assignable to primitives? Or, how do I make a scalar class?

前端 未结 3 1818
庸人自扰
庸人自扰 2021-01-21 08:43

I was wondering if it\'s possible to make my

class Time
{
    public:
        Time();

        explicit
        Time(
            const double& d);

                


        
3条回答
  •  一整个雨季
    2021-01-21 09:11

    You should declare operator double () const to make Time convertible to double. There is no way to overload the assignment operator for primitive types.

提交回复
热议问题