Overloaded operator += using pointer
From: Tony Johansson (johansson.andersson_at_telia.com)
Date: 04/30/04
- Next message: Kevin Chen: "Re: Header file + implementation file with template"
- Previous message: Martin Gieseking: "Re: Header file + implementation file with template"
- Next in thread: Martin Gieseking: "Re: Overloaded operator += using pointer"
- Reply: Martin Gieseking: "Re: Overloaded operator += using pointer"
- Reply: Jeff Schwab: "Re: Overloaded operator += using pointer"
- Reply: Paul: "Re: Overloaded operator += using pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 30 Apr 2004 09:53:03 GMT
Hello Experts!!
Assume you have the following definition of class Array
class Array
{
public:
Array (int antal=0);
Array(const Array& v);
const Array* operator+= (const Array& v)
{
for(int i=0; i<ant; i++)
p[i] += v.p[i];
returning (this); //here you are returning a pointer
}
private:
int *p;
int ant;
};
In main you do the following
main()
{
Array a1(5); //Instansiate the object a1 of class array
Array a2(5) //Instansiate the object a2 of class array
// Assume you have code that load the dynamic array p in object a1 and
// object a2 with some values.
a1 += a2; //calling the overloaded operator += which will return a
pointer
}
Now to my question the overloaded operator += will return a pointer because
the return type is
Array* but how can the receiving object which is a1 in main receive a
pointer(which is an address) when the object a1 is not declared as a
pointer.
I know I can use a reference instead so you don't have to mentioned anything
about that.!!
//Tony
- Next message: Kevin Chen: "Re: Header file + implementation file with template"
- Previous message: Martin Gieseking: "Re: Header file + implementation file with template"
- Next in thread: Martin Gieseking: "Re: Overloaded operator += using pointer"
- Reply: Martin Gieseking: "Re: Overloaded operator += using pointer"
- Reply: Jeff Schwab: "Re: Overloaded operator += using pointer"
- Reply: Paul: "Re: Overloaded operator += using pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|