Any example of operator overloading?

B

Bo Yang

Hi,
I know the only C++ operators which can't be overloaded
are ?:, ., .* and ::

But I did not see any usage of overloading of &(the taking address
operator) and *(the unreference operator). Could you please tell me
is there any usage of these two ones? Thanks!

Regards!
Bo
 
R

red floyd

Bo said:
Hi,
I know the only C++ operators which can't be overloaded
are ?:, ., .* and ::

But I did not see any usage of overloading of &(the taking address
operator) and *(the unreference operator). Could you please tell me
is there any usage of these two ones? Thanks!

This looks like homework, but I'm in a reasonably good mood tonite.

operator*() is often used in smart pointers. See std::auto_ptr<>.
Also to dereference iterators.

operator&() is used by proxy classes.
 
Æ

æ¨ æ³¢

This looks like homework, but I'm in a reasonably good mood tonite.

This is not a homework, :) I think about this when I was reading
operator*() is often used in smart pointers. See std::auto_ptr<>.
Also to dereference iterators.

operator&() is used by proxy classes.

Could you please give me an example about this usage, I can't
understand how this help a proxy classes?
Thanks!

Regards!
Bo
 
S

SeanW

Hi,
  I know the only C++ operators which can't be overloaded
are ?:, ., .* and ::

  But I did not see any usage of overloading of &(the taking address
operator) and *(the unreference  operator). Could you please tell me
is there any usage of these two ones? Thanks!

Google Code Search found many thousands of real-world
usages of those overloads, using the regular expression
"operator[*&]\s*\(\s*\)". Check 'em out:

http://www.google.com/codesearch?q=operator[&*]\s*\(\s*\)+lang:c++

Sean
 
A

AnonMail2005

Hi,
  I know the only C++ operators which can't be overloaded
are ?:, ., .* and ::

  But I did not see any usage of overloading of &(the taking address
operator) and *(the unreference  operator). Could you please tell me
is there any usage of these two ones? Thanks!

Regards!
Bo

In the C++ standard library the string class overloads '+' and '+='
operators.
I believe that the standard library complex class overloads most, if
not all, of the arithmetic operators.

HTH
 
S

SeanW

In the C++ standard library the string class overloads '+' and '+='
operators.
I believe that the standard library complex class overloads most, if
not all, of the arithmetic operators.

The OP specifically asked about overloading
unary & and *.

Sean
 
P

Paul N

Hi,
  I know the only C++ operators which can't be overloaded
are ?:, ., .* and ::

  But I did not see any usage of overloading of &(the taking address
operator) and *(the unreference  operator). Could you please tell me
is there any usage of these two ones? Thanks!

Regards!
Bo

You might like to take a look at http://www.panix.com/~elflord/cpp/list_howto/
which is a tutorial about linked lists. While it's not perfect,
there's plenty of good stuff in there, including (in the "iterators"
section) overloading the * operator.
 
Æ

æ¨ æ³¢

Thanks a lot for all your replies. I have find some examples in
codesearch, that's very useful and thanks again!

Regards!
Bo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top