C++: Convenient way to access operator[] from within class?
(*this)[bar];
works fine for me.
Use
(*this)[bar]
to call the operator[]
of the instance object.
Assuming bar
is an integer (or can be auto-converted to one), this[bar]
treats the this
pointer as an array and indexes the bar
-th element of that array. Unless this
is in an array, this will result in undefined behavior. If bar
isn't integer-like, expect a compile-time error.