f



Did you ever overload operator ->* ?

Hallo,
As a recent posting of mine on the overloading of operator ->* went
unnoticed and this topic is almost never mentioned in the literature, I
was wondering if anybody ever did overload the pointer to member
dereference operator.

My interest in this topic stems from having recently refactored some
code to substitute plain pointers with boost::shared_ptr, where I had to
replace every occurrence of, say, p->*ptm with (*p).*ptm .

Before asking for this modification on the Boost mailing list, I did a
little research and I realized that the behaviour of an overloaded
operator->* is *not* analogous to the behaviour of an overloaded
operator-> . Thus I started wondering why this was the case, if it
shouldn't be changed, and if changing it would break any existing code.
Hence the question in this message's subject.

Cheers,
Nicola Musatti


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Nicola
6/26/2003 7:16:15 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

1 Replies
423 Views

Similar Articles

[PageSpeed] 3

"Nicola Musatti" <nicola.musatti@objectway.it> writes:

> Hallo,
> As a recent posting of mine on the overloading of operator ->* went
> unnoticed and this topic is almost never mentioned in the literature,
I
> was wondering if anybody ever did overload the pointer to member
> dereference operator.

I have. Supporting pointers to member functions requires generating a
    number of overloads equal to the number of arguments you wish to
    support. 

>
> My interest in this topic stems from having recently refactored some
> code to substitute plain pointers with boost::shared_ptr, where I had
to
> replace every occurrence of, say, p->*ptm with (*p).*ptm .
>
> Before asking for this modification on the Boost mailing list, I did a
> little research and I realized that the behaviour of an overloaded
> operator->* is *not* analogous to the behaviour of an overloaded
> operator-> . Thus I started wondering why this was the case,

D&E 11.5.4 mentions it briefly. If one forgets about pointers to
    member functions (in my experience more often used than pointers
    to data members), operator->* can be overloaded to mimic builtin
    ->* behavior without special rules.

> if it
> shouldn't be changed, and if changing it would break any existing
code.
[snip]

It seems adding operator-> type semantics for operator->* with
    exactly one argument would break no code; currently it cannot be
    overloaded to take only one argument.

IMO the root of this problem is the unnecessary and undesirable
    disunity between member functions and non-member functions.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
llewelly
6/27/2003 6:54:10 PM
Reply: