How to return two values?

前端 未结 4 2227
深忆病人
深忆病人 2021-02-13 10:05

I\'d like to return a Cartesian coordinate (x, y), as two ints. The only way I see is to create a class and return an instance of it.

How to return two value

4条回答
  •  天命终不由人
    2021-02-13 10:41

    You can either return one value directly and return another by reference, as shown in gs's answer, or create a struct type and return that. For example, Cocoa already includes a type to identify points on a 2D plane, NSPoint.

提交回复
热议问题