set04 - Operator overloading Jan. 2000 - ENEL 409 Dr. M....

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

View Full Document Right Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 1 Operator overloading 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
Jan. 2000 - ENEL 409 Dr. M. Moussavi 2 Why Overloading Operators? Why Overloading Operators? Remember the following String class defined in previous lectures: class String { public: String(); String(char *s); private: char * str ; int length; };
Background image of page 2
Jan. 2000 - ENEL 409 Dr. M. Moussavi 3 Why Overloading Operators? Why Overloading Operators? int main() { String s1 (“ABC”); String s2 (“XY”); String s3; s3 = s1 + s2; // POINT TWO …. } Not allowed unless that operator + is overloaded for class String.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 4 Operator Overloading Operator Overloading A class designer can provide a set of operators to work with objects of the class. This can be achieved by defining an operator function. An operator function need not to be a member function, but it must take at least one class argument. This prevents the programmer from overloading the behavior of operators for built- in data types.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/10/2011 for the course ENEL 409 taught by Professor Moussavi during the Fall '11 term at University of Calgary.

Page1 / 12

set04 - Operator overloading Jan. 2000 - ENEL 409 Dr. M....

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

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