My intentions of this code is to use overloaded operators for assignment, addition, subtraction and multiplication of polynomials. What I have done so far are the assignment, addition overloaded operators but I am receiving errors. - Thanks
This is the error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
polynomial.cpp: In member function ‘Polynomial& Polynomial::operator+=(const Polynomial&)’:
polynomial.cpp:67:13: error: cannot convert ‘float*’ to ‘float’ in assignment
*newArr = newfloat[Capacity];
^
polynomial.cpp: In function ‘const Polynomial operator+(const Polynomial&)’:
polynomial.cpp:81:3: error: invalid use of ‘this’ in non-member function
*this += poly1;
^
polynomial.cpp:82:10: error: invalid use of ‘this’ in non-member function
return *this;
^
polynomial.cpp: In member function ‘Polynomial& Polynomial::operator=(const Polynomial&)’:
polynomial.cpp:94:3: error: ‘newArr’ was not declared in this scope
*newArr = newfloat[this->Capacity];
^
float Value; // the compiler reserves a place for the Value of the size of float (4 Bytes)
float* ptrValue; // the compiler reserves a place for ptrValue of the size of a pointer (4 Bytes in a 32 Bit System). ptrValue has to be initialized else it points anywhere randomly.
ptrValue = &Value; // ptrValue points now to the address of "Value"
Value = 1.0; // puts the value 1.0 to the place of the address of Value
*ptrValue = 2.0; // puts the value 2.0 to the place where ptrValue points to. In this case it overwrites the Value
So where does ptrValue = &Value; go in the program?
Anywhere you want to store the address of an object called Value. You don't actually have anything called Value in your coce. Necip was giving you examples of how to use pointers.