#include <iostream>
using namespace std;
class CVector {
public:
int x, y;
CVector () {}
CVector (int a, int b) : x(a), y(b) {}
};
CVector operator+ (const CVector & lhs, const CVector & rhs) {
CVector temp;
temp.x = lhs.x + rhs.x;
temp.y = lhs.y + rhs.y;
return temp;
}
int main(int argc, char const *argv[])
{
CVector foo (3, 1);
CVector bar (1, 2);
CVector result;
result = foo + bar;
cout << result.x << ", " << result.y << "\n";
return 0;
}
c++重载操作符续
最新推荐文章于 2025-09-08 21:29:33 发布
