#include #include using namespace std; class cVektori { double x,y; public: // cVektori() : x(0), y(0) { } cVektori(double ix=0,double iy=0) { aseta(ix,iy); } virtual void aseta(double ix,double iy) { x = ix; // cVektori *this; (*this).x y = iy; } virtual void tulosta() const { cout << "(" << getX() << "," << y << ")"; } double getX() const { return x; } // saantimetodi cVektori summa(const cVektori &v2) { cVektori apu; apu.x = x + v2.x; apu.y = y + v2.y; return apu; // return cVektori(x + v2.x, y + v2.y); } // void summa(const cVektori &v2,cVektori &v3) { void summa(cVektori v2,cVektori &v3) { v3.x = x + v2.x; v3.y = y + v2.y; } // cVektori operator+(const cVektori &v2) { return summa(v2); } }; int main() { cVektori v1(4,2); cVektori v2(1.0,1); cVektori v3; v1.tulosta(); cout << "\n"; v2.tulosta(); cout << "\n"; v3.tulosta(); cout << "\n"; v3 = v1 + v2; v3 = v1.summa(v2); v1.summa(v2,v3); // v3.summa(v1,v2); v3.tulosta(); cout << "\n"; cout << v1.getX(); return 0; }