#include using namespace std; // declaration class vector { private: float x,y,z; public: vector(float a=0, float b=0, float c=0) { x=a; y=b; z=c; }// vector() ~vector() {} // nothing to do :) void prtVec(); void getVec(float &a, float &b, float &c) { a=x; b=y; c=z; }// getVec() };// class vector // definitions void vector::prtVec() { cout << x << ", " << y << ", " << z << endl; }// prtVec() // standalone fn vector sum(vector& a, vector& b) { float x0,y0,z0,x1,y1,z1; a.getVec(x0,y0,z0); b.getVec(x1,y1,z1); return vector(x0+x1,y0+y1,z0+z1); }// sum() // standalone operator overloading, IDENTICAL to // sum() above! vector operator+(vector& a, vector& b) { float x0,y0,z0,x1,y1,z1; a.getVec(x0,y0,z0); b.getVec(x1,y1,z1); return vector(x0+x1,y0+y1,z0+z1); }// operator+() int main() { vector v1(1,2,3); // constructed with 0,0,0 v1.prtVec(); vector v2(2,4,6); v2.prtVec(); vector v3 = sum(v1,v2); v3.prtVec(); vector v4(-2,-4,-6); v4.prtVec(); vector v5 = v3+v4; // vector version of +, ie our overloaded op definition v5.prtVec(); vector v6(3,6,9); v6.prtVec(); vector v7 = operator+(v5,v6); // "operator+" is an invokable function! v7.prtVec(); return 0; }// main()