#include using namespace std; struct Vector { double x; double y; }; // 重载 + 运算 Vector operator + (Vector a, Vector b) { Vector s; s.x = a.x + b.x; s.y = a.y + b.y; return s; } // 重载输出 << ostream& operator << (ostream& o, Vector a) { o << "(" << a.x << ", " << a.y << ")"; return o; } int main() { Vector a, b; a.x = 1; a.y = 2; b.x = 10; b.y = 11; Vector s = a + b; cout << s.x << ", " << s.y << endl; operator << (cout, s) << endl; cout << s << endl << endl; return 0; }