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

前端 未结 4 1088
星月不相逢
星月不相逢 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条回答
  •  温柔的废话
    2021-02-05 03:30

    Other answers seams to miss the obvious solution : add a function to convert CGPoint into CGSize. Off course, that is not exactly what you want (size = point), but since you can not modify either of two classes, this is the only way :

    CGSize ToSize( const CGPoint &pt )
    {
      CGSize res = ...
      // do the conversion
      return res;
    }
    

提交回复
热议问题