operator[][] C++

前端 未结 5 1396
佛祖请我去吃肉
佛祖请我去吃肉 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:10

    There is no operator [][]: that's two [] operations in a row. You could:

    • Have Object::operator[] return an object of a second class representing a row, which has its own operator[] method that takes a column number;
    • Write a get(int row, int column) method and use that instead of operator overloading. I'd recommend this unless your object absolutely has to behave like an array.

提交回复
热议问题