I'm writing a container class.
Is there a way to access the [] operator in the class itself, without dereferencing the this pointer?
ie: i'm finding i have to do this:
(*this)["blah"] = "123";
i can't seem to do this (compilation errors):
mycontainer::["blah"] = "123";
or this:
superclass::["blah"] = "123";
is the dereferencing necessary? i can live with it, but is it the most efficient way of doing it, performance-wise?
cheers
tristen
You have to. You can't access the current class in a function without using this, so you would have to deference it eventually.
if you don't want to explicitly dereference this
you can call member operators as functions: operator[]("blah") = "123"
awesome bazzy, that's great, thanks.
Though that way you still dereference this, you just don't do it explicitly.
oh? sorry, i'm not sure what you mean, does the following dereference "this"?
this->operator[]("blah") = "123";
or should i be doing it a different way, maybe:
supercontainer::operator[]("blah") = "123";
this->
is the same as (*this).