Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overloading operator->*() and operator->()

Reply
Thread Tools

overloading operator->*() and operator->()

 
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-20-2009
Can anyone give me a example of how to overload those two operators
and basic usage please ?
And the what is the difference between operator->*() , operator->()
and operator.() , operator.*() (those two can't be overloaded).

Thanks in advance.
Gob00st
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 7:48*am, (E-Mail Removed) wrote:
> Can anyone give me a example of how to overload those two operators
> and basic usage please ?
> And the what is the difference between operator->*() , operator->()
> and operator.() , operator.*() (those two can't be overloaded).
>


What book are you reading that doesn't discuss pointers to members?
 
Reply With Quote
 
 
 
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 4:39*pm, red floyd <(E-Mail Removed)> wrote:
> On Feb 20, 7:48*am, (E-Mail Removed) wrote:
>
> > Can anyone give me a example of how to overload those two operators
> > and basic usage please ?
> > And the what is the difference between operator->*() , operator->()
> > and operator.() , operator.*() (those two can't be overloaded).

>
> What book are you reading that doesn't discuss pointers to members?


MSDN...

Why those two people above just ask me question without trying to help
a bit?
Of course its pointers to members operator ,but I just trying to find
a example of overloading them.

So any input is appreciated...
Gob00st
 
Reply With Quote
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 4:55*pm, (E-Mail Removed) wrote:
> On Feb 20, 4:39*pm, red floyd <(E-Mail Removed)> wrote:
>
> > On Feb 20, 7:48*am, (E-Mail Removed) wrote:

>
> > > Can anyone give me a example of how to overload those two operators
> > > and basic usage please ?
> > > And the what is the difference between operator->*() , operator->()
> > > and operator.() , operator.*() (those two can't be overloaded).

>
> > What book are you reading that doesn't discuss pointers to members?

>
> MSDN...
>
> Why those two people above just ask me question without trying to help
> a bit?
> Of course its pointers to members operator ,but I just trying to find
> a example of overloading them.
>
> So any input is appreciated...
> Gob00st


So any input other than complaining / sarcasm is appreciated...
 
Reply With Quote
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 5:24*pm, Jeff Schwab <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On Feb 20, 4:55 pm, (E-Mail Removed) wrote:
> >> On Feb 20, 4:39 pm, red floyd <(E-Mail Removed)> wrote:

>
> >>> On Feb 20, 7:48 am, (E-Mail Removed) wrote:
> >>>> Can anyone give me a example of how to overload those two operators
> >>>> and basic usage please ?
> >>>> And the what is the difference between operator->*() , operator->()
> >>>> and operator.() , operator.*() (those two can't be overloaded).
> >>> What book are you reading that doesn't discuss pointers to members?
> >> MSDN...

>
> >> Why those two people above just ask me question without trying to help
> >> a bit?
> >> Of course its pointers to members operator ,but I just trying to find
> >> a example of overloading them.

>
> >> So any input is appreciated...
> >> Gob00st

>
> > So any input other than complaining / sarcasm is appreciated...

>
> It's basically just a pain in the neck to explain, and isn't something
> that comes up often enough for people to have examples at hand. *If this
> is a purely academic question, Google is probably your best bet. *If,
> OTOH, you have a real-world situation that needs a practical answer, it
> would be helpful if you could explain it.


I admit its may not a practical question since I have never overloaded
these two operators before.
That's why I am curious enough to post this thread to see if anyone
have actually had any practical usage them.

Here is my tentative code of overloading operator->*(), it works , but
its ugly. Any one know how to use it correctly?
class Base;
typedef void (Base::*PMF) (int);

class Base {
public:
void foo(int a)
{
cout << "base::foo" << endl;
}

void operator->*(PMF p)
{
cout << "ponter to member operator overloaded" << endl;
(this->*p)(1);
}
};

int main()
{
PMF pmf;
Base b;
pmf = &Base::foo;
Base* pb = &b;
pb->operator->*(pmf); //here my overloading operator->* has been
called, but its ugly
(pb->*pmf)(1); //why this doesn't invoke my overloaded operator-
>*

return 0;
}

Thanks.
Gob00st



 
Reply With Quote
 
SG
Guest
Posts: n/a
 
      02-20-2009
On 20 Feb., 18:51, (E-Mail Removed) wrote:
> * * * * Base* pb = &b;
> * * * * pb->operator->*(pmf);
> * * * * (pb->*pmf)(1);


You overloaded ->* on base. But the type of "pb" is of "base*".
That's why.

Cheers!
SG
 
Reply With Quote
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 6:22*pm, SG <(E-Mail Removed)> wrote:
> On 20 Feb., 18:51, (E-Mail Removed) wrote:
>
> > * * * * Base* pb = &b;
> > * * * * pb->operator->*(pmf);
> > * * * * (pb->*pmf)(1);

>
> You overloaded ->* on base. But the type of "pb" is of "base*".
> That's why.
>
> Cheers!
> SG


Thanks SG, it's the most constructive reply in this thread.
But operator->*() requires it first argument to be a pointer to the
type which is overloading.
Can I can not invoke operator->* with b.

I can only write (b.*pmf)(1) with object b which should be calling
operator.*() ,but it cannot be overloaded. I am getting confused.

What is the correct overloading of operator->*() and usage?
Thanks,
Gob00st
 
Reply With Quote
 
Christof Donat
Guest
Posts: n/a
 
      02-20-2009
Hi,

> Can anyone give me a example of how to overload those two operators
> and basic usage please ?
> And the what is the difference between operator->*() , operator->()
> and operator.() , operator.*() (those two can't be overloaded).


operator->() is usually used for stuff like smart pointers:

Christof


 
Reply With Quote
 
Sana
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 2:17*pm, (E-Mail Removed) wrote:
> On Feb 20, 6:22*pm, SG <(E-Mail Removed)> wrote:
>
> > On 20 Feb., 18:51, (E-Mail Removed) wrote:

>
> > > * * * * Base* pb = &b;
> > > * * * * pb->operator->*(pmf);
> > > * * * * (pb->*pmf)(1);

>
> > You overloaded ->* on base. But the type of "pb" is of "base*".
> > That's why.

>
> > Cheers!
> > SG

>
> Thanks SG, it's the most constructive reply in this thread.
> But operator->*() requires it first argument to be a pointer to the
> type which is overloading.


SG is right. You overloaded operator->* for the type not for the
_pointer_to_type_ (actually you cannot do that) so you have to use
operator->* with an object and not a pointer


> Can I can not invoke operator->* with b.


yes, you can:

b->*pmf;

those operators (-> and ->*) are usually used with objects that must
behave like pointers. such an example would be a smart pointer

--
sana


 
Reply With Quote
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-20-2009
On Feb 20, 8:18*pm, Sana <(E-Mail Removed)> wrote:
> On Feb 20, 2:17*pm, (E-Mail Removed) wrote:
>
>
>
>
>
> > On Feb 20, 6:22*pm, SG <(E-Mail Removed)> wrote:

>
> > > On 20 Feb., 18:51, (E-Mail Removed) wrote:

>
> > > > * * * * Base* pb = &b;
> > > > * * * * pb->operator->*(pmf);
> > > > * * * * (pb->*pmf)(1);

>
> > > You overloaded ->* on base. But the type of "pb" is of "base*".
> > > That's why.

>
> > > Cheers!
> > > SG

>
> > Thanks SG, it's the most constructive reply in this thread.
> > But operator->*() requires it first argument to be a pointer to the
> > type which is overloading.

>
> SG is right. You overloaded operator->* for the type not for the
> _pointer_to_type_ (actually you cannot do that) so you have to use
> operator->* with an object and not a pointer
>
> > Can I can not invoke operator->* with b.

>
> yes, you can:
>
> b->*pmf;
>
> those operators *(-> and ->*) are usually used with objects that must
> behave like pointers. such an example would be a smart pointer
>
> --
> sana- Hide quoted text -
>
> - Show quoted text -


Yes, its works. Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Overloading __init__ & Function overloading Iyer, Prasad C Python 4 09-30-2005 08:01 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 03:59 PM
Overloading __init__ & Function overloading Iyer, Prasad C Python 3 09-30-2005 02:17 PM
Re: Overloading __init__ & Function overloading Steve Holden Python 0 09-30-2005 01:58 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 01:53 PM



Advertisments