c++重载操作符续

来源:互联网 发布:网络新词语大全 编辑:程序博客网 时间:2024/06/05 20:31
#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;}
原创粉丝点击