#include #include #include using namespace std; template class Vec2 { private: num x,y; public: Vec2(num _x, num _y){ x=_x; y=_y; } string toString(){ stringstream s; s << "[" << x << ", " << y << "]"; return s.str(); } Vec2 add(const Vec2& vec){ return Vec2(x+vec.x, y+vec.y); } num multiply(const Vec2& vec){ return (float)x*vec.x + (float)y*vec.y; } }; int main(){ Vec2 vec1 = Vec2(5.5f,1.2f); Vec2 vec2 = Vec2(3.4f,4.2f); Vec2 vec3 = vec1.add(vec2); cout << vec3.toString() << endl; }