// This example illustrates overloading the plus (+) operator. #include <iostream> using namespace std; class complx { double real, imag; public: 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 { complx result; result.real = (this->real + c.real); result.imag = (this->imag + c.imag); cout << "the line when occurs this operation was: " << line << endl; //this line refers to the line in main function return result; } int main() { complx x(4,4); complx y(6,6); complx z = x + y; // calls complx::operator+() -> ******THIS IS THE LINE******* }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)