0

I can't figure out the operator overloading...

Can any body explain the operator overloading and give me the answer of queue management 2

28th Jul 2023, 5:23 PM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
1 Respuesta
+ 3
the main idea behind “Operator overloading” is to use C++ operators with class variables or class objects. Example: class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0) { real = r; imag = i; } // This is automatically called when '+' is used with // between two Complex objects Complex operator+(Complex const& obj) { Complex res; res.real = real + obj.real; res.imag = imag + obj.imag; return res; } void print() { cout << real << " + i" << imag << '\n'; } }; int main() { Complex c1(10, 5), c2(2, 4); Complex c3 = c1 + c2; c3.print(); }
29th Jul 2023, 11:49 AM
JaScript
JaScript - avatar