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

前端 未结 3 1820
庸人自扰
庸人自扰 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:29

    You have to write/override an operator. In this case the cast-operator. Define a method

    operator double() { return double_however_computed_from_your_time; };
    

提交回复
热议问题