Is it possible to write auto-cast operator outside a struct?

前端 未结 4 1139
星月不相逢
星月不相逢 2021-02-05 02:53

The exact situation is next: I have defined in system API structs CGPoint and CGSize, and I want to be able to write my_point = my_size. I

4条回答
  •  Happy的楠姐
    2021-02-05 03:17

    When you assign a CGSize to a CGPoint - what happens? Distil that into some operator and there you have it - for example

    CGPoint& operator|=(CGPoint& cPoint, CGSize const& cSize)
    {
      // now set attributes of cPoint that you can extract from cSize
    
      return cPoint;
    }
    

    What's so difficult about this? Here is an example: http://www.ideone.com/FZN20

提交回复
热议问题