#include <iostream>
using namespace std;
class Vektor {
public:
int x, y;
Vektor(int a, int b) {
x = a;
y = b;
}
};
Vektor& Vektoraddition(Vektor& vec1, Vektor& vec2) {
Vektor Vektorres(0,0);
Vektorres.x = vec1.x + vec2.x;
cout << Vektorres.x << endl;
Vektorres.y = vec1.y + vec2.y;
cout << Vektorres.y << endl;
return Vektorres;
}
int main() {
Vektor Vektor1(2, 3);
Vektor Vektor2(3, 3);
Vektor& Vecresult = Vektoraddition(Vektor1, Vektor2);
cout << Vecresult.x << ", " << Vecresult.y << endl;return 0;
}
当我逐步进行调试时,“ Vecresult.x”和“ Vecresult.y”的结果是有效的,但是,当我想将其打印为“ Vecresult.y”的结果时,它将以某种方式变为随机数。希望有人可以帮助我...