定义[] =运算符

jcl*_*ncy 4 c++ arrays operator-overloading

我正在编写一个Grid类,其元素是Points - 一个(int)网格,每个网格的正方形都有一个(双)点.我已经定义了这个(高度值存储在别处):

Point &operator[](Point p) { return floor(get_x(p)) + height * floor(get_y(p)); }
Run Code Online (Sandbox Code Playgroud)

我想定义赋值运算符.怎么会这样呢?它是根据[]运营商自动定义的吗?

到目前为止我有

Point &operator[]=(Point p, Point q) { data[floor(get_y(p)) * height + floor(get_x(p))] = q; }
Run Code Online (Sandbox Code Playgroud)

但这似乎是一个循环的定义.

Nim*_*Nim 7

这不是它的工作原理,[]运算符应该返回该索引处元素的引用,并且该元素(类型)应该支持operator=(即Point::operator=)