#include using namespace std; class point { public: class point_iterator { public: int place; point *class_we_came_from; point_iterator(int p, point* cwcf) : place(p), class_we_came_from(cwcf) {} point_iterator& operator++() { place++; return *this; } bool operator!=(const point_iterator& other) const { return place != other.place; } float& operator*(){ if(place == 0) return class_we_came_from->x; if(place == 1) return class_we_came_from->y; if(place == 2) return class_we_came_from->z; cout << "We have a problem\n"; return class_we_came_from->x; } }; float x, y, z; point(float ix, float iy, float iz) : x(ix), y(iy), z(iz) {} point operator+(point other){ return point(x + other.x, y + other.y, z + other.z); } point_iterator begin() { return point_iterator(0, this); } point_iterator end() { return point_iterator(2, this); } }; ostream& operator<<(ostream& out, const point& p){ return out << "(" << p.x << ", " << p.y << "," << p.z << ")"; } int main(){ point a(3, 6, 1); point b(17, -2, 1); point c = a + b; cout << c << endl; for(auto &item : c) item *= 2; cout << c << endl; }