Guest
Posts: n/a

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

Gob00st

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?

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

So any input is appreciated...
Gob00st

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
>
> So any input is appreciated...
> Gob00st

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

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

>
> >> 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
> 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;
called, but its ugly
(pb->*pmf)(1); //why this doesn't invoke my overloaded operator-
>*

return 0;
}

Thanks.
Gob00st

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

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

But operator->*() requires it first argument to be a pointer to the
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.

Thanks,
Gob00st

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

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

>
> But operator->*() requires it first argument to be a pointer to the

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

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

>
> 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.