Call it like you are, or like
1 2 3
|
this->operator[]( key ) = val;
// or
operator[]( key ) = val;
|
Writing another function to do exactly the same thing is just extra baggage,
and, while awkward, neither of the above syntaxes are unclear in the first
place.
Having said that, a reasonable paradigm for accessor functions is that the public
accessor function -- the one called by your users -- should first validate parameters,
then call a private accessor function (which does not validate parameters) to get
the actual value.
Then, when you need to call the accessor from within your own object, you call
the private method under the assumption that it is the caller's responsibility to
get the parameters right, which usually incurs no additional overhead.
This paradigm can be useful when validation of parameters is expensive relative
to the cost of access. std::bitset<>for example has both "checked" and
"unchecked" public accessor methods for this reason. You'll easily see a 2x or
more performance boost by using the unchecked methods.