Operator[][] overload

前端 未结 18 1874
轮回少年
轮回少年 2020-11-22 05:46

Is it possible to overload [] operator twice? To allow, something like this: function[3][3](like in a two dimensional array).

If it is pos

18条回答
  •  悲&欢浪女
    2020-11-22 06:16

    An expression x[y][z] requires that x[y] evaluates to an object d that supports d[z].

    This means that x[y] should be an object with an operator[] that evaluates to a "proxy object" that also supports an operator[].

    This is the only way to chain them.

    Alternatively, overload operator() to take multiple arguments, such that you might invoke myObject(x,y).

提交回复
热议问题