On Feb 4, 5:55 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Dario Saccavino:
> > It seems to me that operator->* is overloadable in C++ (just like
> > operator->), and it should be useful to implement in smart pointer
> > classes.
> > However, I haven't found its implementation either in the standard
> > weak_ptr class, or in any boost smart pointer. Was it intentionally
> > left out of those headers?
> > Actually there's a workaround: just write
> > (ptr.operator->())->*memptr
> > instead of
> > ptr->*memptr
> > But it looks very ugly. How am I supposed to use member pointers with
> > smart pointers?
> In general it's not a good idea to use member pointers.
Except when the alternatives are worse

.
Seriously, I've used them a couple of times in the past, and
almost every time, I've ended up going back, and reconverting
the code to use delegates. Which requires a bit more
boilerplate code, but is more flexible and more easily
understood by other programmers.
As for why std::auto_ptr (and the Boost smart pointers) don't
support them, the main reason is probably because they're an
open set. You'd need something like:
template< typename U >
??? operator->*( U op ) ;
And I'm not sure what you'd have to put in place of the ??? if U
was a pointer to member function---the result of p->*pmf is a
bound member function, and C++ doesn't have a type for it. (And
of course, the very few times you might want to use pointers to
members, it will be with a pointer to member function.)
Anyway, given that it's neither useful nor implementable, I can
sort of understand it not being present, even if it is an
incompatibility with raw pointers.
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34