K
kanze
Say you have a class Foo. The operator[] that is non-const returns a
proxy. There is a function operator const Foo&() const. Then there
is a function void operator=(const Foo&). What about other member
functions of class Foo? So that we can say
EnvelopeClass env;
env["abc"]; // returns EnvelopeClass::reference, which is conceptually a
Foo&
env["abc"] = Foo(3); // ok
env["abc"].memfun(); // oops
For the last line to work, class EnvelopeClass::reference should have
a member function memfun() because class Foo has such a function.
Then we have to duplicate the entire interface of class Foo inside
Foo::reference. Quite a nuisance.
This is a known problem. It is a major motivation behind the desire to
be able to overload operator.(). In the meantime, about the best you
can do is overload operator-> on the proxy, and require your users to
write things like:
env[ "abc" ]->memfun() ;
It exposes the fact that you are using a proxy, but until you can
overload operator.(), it is the best you can do.