Let's say that I've got a class that wraps a raw array. I've implemented the operator[] method which is great. In implementing the at() method, I decided that I'd just use:.Code:(*this)[index]
Is that weird C++?
Let's say that I've got a class that wraps a raw array. I've implemented the operator[] method which is great. In implementing the at() method, I decided that I'd just use:.Code:(*this)[index]
Is that weird C++?
Nah, but I think you know the alternative.
this->operator[](index);
It isn't weird at all. In fact, it's the only way it should be done(in my opinion)...
What is wrong with this:
operator[](index)
This is just a style preference, but I prefer not to write this everywhere in C++.
Not wrong. It's a matter of style. But again, the reason we have operators is so that we can use more natural style and (*this)[idx] is more natural.
I think the weird thing here is that "this" is a pointer. But as you know, there's history there.
Well, you can
Code:MyClass& self = *this;
self[123] = 345;