|
|
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
|
|
|
|
Reply
|
Nicola
|
6/26/2003 7:16:15 PM |
|
"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
|
|
|
|
Reply
|
llewelly
|
6/27/2003 6:54:10 PM
|
|
|
1 Replies
123 Views
(page loaded in 0.05 seconds)
Similiar Articles: Non-member operator overloading, linker complains - comp.lang.c++ ...C++ Tutorials - Lesson 24: Operator Overloading Operator overloading is the ability to tell the compiler how to ... the operation, the function should return a non ... of ... sizeof implementation - comp.lang.cOverloading operators new and delete - comp.lang.c++.moderated ..... code: void * CLASS_A ... an implementation-specific "mangler" shouldn't be a problem -- if you ever do ... How to overload subsref correctly? - comp.soft-sys.matlab ...enum and operator++ - comp.lang.c++ > > REH- Hide quoted text - > > - Show quoted text - Hi You are right. ... C++ - how to overload enum operator. . 1 Answers are ... ptr versus const ptr& - comp.lang.c++.moderatedSame as other assignment operator overload: use a temporary and swap with it. Obviously, you ... Did you consider that the first ... There is no guarantee that you will ever ... ANN: C++/Tk - comp.lang.c++.moderatedBut emulating one language in another (in this case by abusing operator overloading) hardly ever works. Before you invest much time into this approach you might consider ... enum and operator++ - comp.lang.c++>No amount of "increment"-ing will ever produce Max_. That much is true. > >> If you replace // do ... enum operator overload ambiguity - comp.lang.c++.moderated ... ... left-hand operand of comma has no effect - comp.lang.c++ ...What you might want is to define the operator comma in your class, like so ... // do what you did earlier with 'left' and ... meaning is a+b, then why don't you simply overload ... The nightmare begins... - comp.databases.filemakerAnd Excel does not only permit to export html format (with a huge overload of ... Did you ever manage to migrate databases from SQL, > > including create tables? Const constructor - comp.lang.c++.moderated... one I know in the UK C++ Standards world has ever ... void foo(const ArraySilce& s); > > Sorry, did you ... operator<< overload for ostream. Copy and assignment were left ... Removing duplicates from within sections of a file - comp.lang.awk ...Did you mean to use the double equals ... contained in the book that you will never, ever get ... print;a[$0]=""}' file >>> >>> > >>You can read up on the "in" operator ... Overloading '='The most confusing aspect of using operator overloading in Perl is undoubtedly the ... So why would we ever need to overload `=', then, if Perl is smart enough to do all ... C++ overload operator new question - Stack OverflowOverloading operator new gives you a chance to control where an object lives in ... Does it ever make sense to overload unary operator &? 7/15/2012 1:19:41 PM
|
|
|
|
|
|
|
|
|