Overload dereference operator

前端 未结 3 1695
醉梦人生
醉梦人生 2021-02-08 20:27

I\'m trying to overload the dereference operator, but compiling the following code results in the error \'initializing\' : cannot convert from \'X\' to \'int\':

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-08 21:13

    If you want the original code to work, you need to overload the int-cast operator for your class:

    operator int() const { return 5; }
    

提交回复
热议问题