Q&A
Q1: | Why would you overload an operator when you can just create a member method? |
A1: | It is easier to use overloaded operators when their behavior is well understood. It enables your class to mimic the functionality of the built-in types. |
Q2: | What is the difference between the copy constructor and the assignment operator? |
A2: | The copy constructor creates a new object with the same values as an existing object. The assignment operator changes an existing object so that it has the same values as another object. |
Q3: | What happens to the int used in the postfix operators? |
A3: | Nothing. That int is never used except as a flag to overload the postfix and prefix operators. |
Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.