• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Operator overloading (oop)lecture19
 

Operator overloading (oop)lecture19

on

  • 386 views

 

Statistics

Views

Total Views
386
Views on SlideShare
386
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Operator overloading (oop)lecture19 Operator overloading (oop)lecture19 Presentation Transcript

    • Other BinaryOther Binary operatorsoperators►Overloading comparison operators:Overloading comparison operators: class Complex{class Complex{ public:public: bool operator == (const Complex & c);bool operator == (const Complex & c); //friend bool operator == (const//friend bool operator == (const //Complex & c1, const Complex & c2);//Complex & c1, const Complex & c2); bool operator != (const Complex & c);bool operator != (const Complex & c); //friend bool operator != (const//friend bool operator != (const //Complex & c1, const Complex & c2);//Complex & c1, const Complex & c2); …… };};
    • Other BinaryOther Binary operatorsoperatorsbool Complex::operator ==(constbool Complex::operator ==(const Complex & c){Complex & c){ ifif(((real == c.real) &&(real == c.real) && (img == c.img)(img == c.img))){{ return true;return true; }} elseelse return false;return false; }}
    • Other BinaryOther Binary operatorsoperatorsbool operator ==(constbool operator ==(const Complex& lhs, const Complex& rhs){Complex& lhs, const Complex& rhs){ ifif(((lhs.real == rhs.real) &&(lhs.real == rhs.real) && (lhs.img == rhs.img)(lhs.img == rhs.img))){{ return true;return true; }} elseelse return false;return false; }}
    • Other BinaryOther Binary operatorsoperatorsbool Complex::operator !=(constbool Complex::operator !=(const Complex & c){Complex & c){ ifif(((real != c.real) ||(real != c.real) || (img != c.img)(img != c.img))){{ return true;return true; }} elseelse return false;return false; }}