using pointer in a friend operator +

G

Guest

Normally, when i define a friend operator + the argument used by the
operator function is references. but i try to use pointer and look like
this:
class A;
friend A operator+( A *a1, A *a2);

I cannot pass through the compiler. get error c2803.
i look up the book<The C++ programming language> ,and i get the reason,
Pointers cannot be used because it is not possible to redefine the
meaning of
an operator applied to a pointer. i don't understand redefine, can you
tell me ,thanks.
 
I

Ian Collins

海风 said:
Normally, when i define a friend operator + the argument used by the
operator function is references. but i try to use pointer and look like
this:
class A;
friend A operator+( A *a1, A *a2);

I cannot pass through the compiler. get error c2803.

Which is?
i look up the book<The C++ programming language> ,and i get the reason,
Pointers cannot be used because it is not possible to redefine the
meaning of
an operator applied to a pointer. i don't understand redefine, can you
tell me ,thanks.
What possible reason could there be to redefine pointer addition? This
is what you are attempting to declare.
 
A

Alf P. Steinbach

* 海风:
Normally, when i define a friend operator + the argument used by the
operator function is references. but i try to use pointer and look like
this:
class A;
friend A operator+( A *a1, A *a2);

The above is not your actual code; please use the copy and paste method
to ensure the code you post is accurate, the same as the code your
compiler complains about (otherwise there's not much point).
I cannot pass through the compiler. get error c2803.
i look up the book<The C++ programming language> ,and i get the reason,
Pointers cannot be used because it is not possible to redefine the
meaning of
an operator applied to a pointer. i don't understand redefine, can you
tell me ,thanks.

You cannot redefine what 'a + b' means when p1 and p2 are both of
built-in type or pointer.

For example, you can't define 'int operator+( int a, int b )'.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top