Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > using pointer in a friend operator +

Reply
Thread Tools

using pointer in a friend operator +

 
 
=?utf-8?B?5rW36aOO?=
Guest
Posts: n/a
 
      08-08-2006
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.

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      08-08-2006
海风 wrote:
> 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.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-08-2006
* 海风:
> 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 )'.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
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




Advertisments