I took this example from http://publib.boulder.ibm.com/infoce...ef/cplr318.htm
// This example illustrates overloading the plus (+) operator.
using namespace std;
complx( double real = 0., double imag = 0.); // constructor
complx operator+(const complx&) const; // operator+()
// define constructor
complx::complx( double r, double i )
real = r; imag = i;
// define overloaded + (plus) operator
complx complx::operator+ (const complx& c) const
result.real = (this->real + c.real);
result.imag = (this->imag + c.imag);
complx z = x + y; // calls complx::operator+()
- What does it do when assigning the values to variables inside the constructor? complx( double real = 0., double imag = 0.);
- What does it do when having const infront of an argument? (const complx&)
- What does it do having const after a signature? (const complx&) const; by the way is this still considered part of the signature?
- Is there such a thing as returning a const?
I felt anyone of these questions would be unworthy of an entire thread so I put them in one. Hopefully I'm not breaking the rules for this.