c++重载运算符

来源:互联网 发布:java读取blob字段 编辑:程序博客网 时间:2024/05/23 01:09
#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&);};CVector CVector::operator + (const CVector& param) {    CVector temp;    temp.x = x + param.x;    temp.y = y + param.y;    return temp;}int main(int argc, char const *argv[]){    CVector foo (1,3);    CVector bar (2, 4);    CVector result;    result = foo + bar;    cout << "result's x: " << result.x << ", " << "result's y: " << result.y << endl;    return 0;}
原创粉丝点击