Unclear use of operator double()

后端 未结 3 1888
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 09:34

I have a Rectangle class with conversion operators to both double and std::string:

class Rectangle
{
public:
    Rectangle         


        
3条回答
  •  独厮守ぢ
    2021-02-07 10:19

    There is nothing special about double-overloading than other primitive types overloadings. In this case, it is the only primitive overload available. The compiler will behave the same for int, char, etc..

    Notice that if we would have more than one primitive type overload the compiler will throw

    error: ambiguous overload for 'operator<<' ...
    

提交回复
热议问题