
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;


template<typename T>
void mySwap(T &i, T &j) {
    T t = i;
    i = j;
    j = t;
}

struct vec {
    double x;
    double y;
    double z;

    vec operator+ (const vec &a) const {
        return vec(x + a.x, y + a.y, z + a.z);
    }

    vec operator* (double s) const {
        return vec(s*x, s*y, s*z);
    }
    vec & operator= (const vec &v)
    {
        cerr << "assignment!!!" << endl;
        x = v.x;
        y = v.y;
        z = v.z;
        return (*this);
    }

    vec &operator+=(const vec &a)
    {
        return *this = *this + a;
    }

    vec(double x, double y, double z) : x(x), y(y), z(z) {
        cerr << "Construction from 3 values" << endl;
    }

    vec(const vec &v) : x(v.x), y(v.y), z(v.z) {
        cerr << "Copy happened" << endl;
    }

    vec() : x(0), y(0), z(0) {
        cerr << "Default construction!" << endl;
    }

    ~vec() {
        cerr << "Being destroyed" << endl;
    }

    double length() const {
        return sqrt(x * x + y * y + z * z);
    }
};

vec operator*(double a, const vec &v) {
    return v*a;
}

std::ostream& operator<< (std::ostream& o, const vec &r) {
    o << r.x << ", " << r.y << ", " << r.z;
    return o;
}

int main()
{
    /*int n;
    int m;
    cin >> n >> m;
    mySwap(n, m);
    cout << n << ' ' << m << endl;*/

    vec v(1, 2, 3);

    v += vec(1, 0, 5);

    cout << (2*v+vec(3,2,1)).length() << endl;

    cout << v << endl;

    vec w = v;

    return 0;
}
