operator[][] C++

前端 未结 5 1386
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 16:24

I\'d like to overload operator[][] to give internal access to a 2D array of char in C++.

Right now I\'m only overloading operator[], which goes

5条回答
  •  囚心锁ツ
    2021-02-15 17:18

    There is no operator[][]. Evaluating a[x][y] first calls operator[] on a, and then operator[] again on the result of that.

    So the operator[] of your object has to return another object with its own operator[], which then will access the requested value.

提交回复
热议问题