如何将坐标合并为一个值并将其返回?

时间:2015-05-16 23:06:51

标签: c++

如上所述,这样做有什么棘手的方法吗? 由于您无法传递数组,我想知道如何将坐标(x / column和y / row)返回给调用对象。 问候。

1 个答案:

答案 0 :(得分:0)

c ++中有很多可能,但我给你一个简单的例子:

 struct coords {
     int x;
     int y;
 };

 int calculate_value_of_x(int y);
 int calculate_value_of_y(int x);
 coords calc_coords() {
     coords c;
     c.x = calculate_value_of_x(c.y);
     c.y = calculate_value_of_y(c.x);
     return c;
 }