Overloading operator=

I am a bit confused with overloading operator=. Here is my function call, not working of course...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Main.cpp
Polynomial test1;
Polynomial test2;
.
.
.
test2 = test1 * test1;


Polynomial.cpp
--------------
Polynomial* Polynomial::operator=(Polynomial& P){
        this._degree = P.getDegree();
	this._coefficients = P.getCoefficients();
	return this;
}

1. If an operator overload is supposed to return this, it should return it as a reference, not a pointer.
2. Polynomial::operator=() should be able to access Polynomial::_degree, so there's no need to call getDegree(). The same goes for _coefficients.
3. P should be a 'const Polynomial &'.
Last edited on
4. this is a pointer - so this->x not this.x
We assume that you already have operator* working, too.
Damn. I knew C# was going to overwrite something. I totally ignored that dot.
Topic archived. No new replies allowed.