lecture-12 - C+ Operator Overloading Object Oriented...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Oriented Programming C++ Operator Overloading R.B. Lenin Winter 2006 DA-IICT C++ Operator Overloading
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Object Oriented Programming C++ Operator Overloading R.B. Lenin Winter 2006 DA-IICT Introduction • Operator overloading – Use traditional operators with user-defined objects – Straightforward and natural way to extend C++ – Requires great care • When overloading misused, program difficult to understand
Background image of page 2
3 Object Oriented Programming C++ Operator Overloading R.B. Lenin Winter 2006 DA-IICT Fundamentals of Operator Overloading • Use operator overloading to improve readability – Avoid excessive or inconsistent usage •F o r m a t – Write function definition as normal – Function name is keyword operator followed by the symbol for the operator being overloaded. operator+ would be used to overload the addition operator ( + )
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Object Oriented Programming C++ Operator Overloading R.B. Lenin Winter 2006 DA-IICT Fundamentals of Operator Overloading (II) • Assignment operator ( = ) – may be used with every class without explicit overloading memberwise assignment
Background image of page 4
5 Object Oriented Programming C++ Operator Overloading R.B. Lenin Winter 2006 DA-IICT Restrictions on Operator Overloading • Most of C++’s operators can be overloaded Operators that can be overloaded + - * / % ^ & | ~ ! = < > += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= && || ++ -- ->* , -> [] () new delete new[] delete[]
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

lecture-12 - C+ Operator Overloading Object Oriented...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online