Lec 5
Lec 5
Lecture
Programing
5
Object (Pass by Value)
MyClass myObject;
myFunction(myObject);
Object (Pass by Reference)
Example:
class Complex
{
public: double real, imag;
Complex operator+(const Complex &other) const
{
Complex result;
result.real = real + other.real;
result.imag = imag + other.imag;
return result;
}
};
• Comparison Operator (==, <= , >= ,!= ) Overloading
Comparison operator overloading in C++ is the process of
defining custom behavior for the standard comparison operators
(==, !=, <, >, <=, >=) when they are applied to instances of
user-defined classes.
Example:
class Complex
{
public:
double real, imag;