I’m writing a class Grid whose elements are Points – an (int) grid each of whose squares has a (double) point in it. I’ve already defined this (the height value is stored elsewhere):
Point &operator[](Point p) { return floor(get_x(p)) + height * floor(get_y(p)); }
and I want to define the assignment operator. How would one go about this? Is it defined automatically based on the [] operator?
So far I have
Point &operator[]=(Point p, Point q) { data[floor(get_y(p)) * height + floor(get_x(p))] = q; }
but that seems like a circular definition.
That’s not how it works, the
[]operator should return a reference the element at that index, and that element (type) should supportoperator=(i.e.Point::operator=)