Re: operator overloading
From: Robert W Hand (rwhand_at_NOSPAMoperamail.com)
Date: 03/29/04
- Next message: B. v Ingen Schenau: "Re: Test string value - please help"
- Previous message: B. v Ingen Schenau: "Re: Dynamic Array dereference problem"
- In reply to: Rappy: "operator overloading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Mar 2004 12:08:39 -0500
On Sat, 27 Mar 2004 21:29:54 +1100, "Rappy" <rapp13@iprimus.com.au>
wrote:
>having probs with addition operator overloading, error message tells me that
>the binary 'operator +' has two many parameters. how can this be? it is
>supposed to add two class operands.
>
>declaration in class:
> const SalesRegister operator +(const SalesRegister& lhs, const
>SalesRegister& rhs);
>
>definition in implementation file:
> const SalesRegister SalesRegister::operator+(const SalesRegister
>¶m)
I assume that the first 'two' is really 'too'. :-)
This construction is a non-static member function, is it not? There
is an implicit object passed to the function. Remember the this
pointer? ;-)
Binary overloaded operators shall be implemented by a non-static
member function with exactly one parameter or by a non-member function
with two parameters. So x+y can be interpreted as x.operator +(y) or
operator +(x, y) depending on which form is declared.
Best wishes,
Bob
- Next message: B. v Ingen Schenau: "Re: Test string value - please help"
- Previous message: B. v Ingen Schenau: "Re: Dynamic Array dereference problem"
- In reply to: Rappy: "operator overloading"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|