|
| Week 7 - Monday, October 2, 2006 to Friday, October 6, 2006 |
| The Big Three and Overloaded Operators |
Comments
We revisit Constructors this week with more depth. The "Big Three" are the Copy Constructor, the operator= assignment operator, and the Destructor. To prevent problems you should define all three for any class that needs any of them. In addition, the Default Constructor should be considered the "Big Fourth", unless you specifically don't want one.
Overloaded Operators are a controversial feature of C++. They are a syntactic convenience, and really are not needed for anything but pretty code. However, they are popular in certain types of C++ classes that mimic the operators of normal C syntax. They are used by the standard libraries of C++. For instance, the <string> class uses overloaded operators to allow you to write:
string hello = "Hello World?";
hello[11] = '!';
A lot of programming language theorists think they are unnecessary, however, and complicate a language a lot for the little improvement in the ease of use. Java did not include overloaded operators, but Microsoft put them back in for C#.
Don't try to learn all the details of overloaded operators! It isn't worth it. Just learn the overall concepts and then use my files StandardFunctions.h and StandardFunctions.cpp to actually create your new classes. If you deviate just a little from the code in these files, overloaded functions don't work well and give all kinds of strange errors. Keep very, very close to the code and the instructions in the comments of these two files. Delete any functions you don't want for your class. You can, of course, add additional functions that are not related to Constructors or Overloaded Operators.
Course Content
Week 7
The Big
Three
Overloaded Operators
Readings
Deitel and Deitel Fifth Edition, ??.
Deitel and Deitel Fourth Edition, ??
Lab
Assignment
Week 7 Test
12 Questions for 4 points, with fractions rounded up.
Only available Friday, October 6th, from 6:00 am to 3:00 am Saturday morning on Angel. It will cover the following material:
| Back to Csc 125 Programming in C++ |
| Scott Badman Office: B132 Phone: 353-2250 sbadman@parkland.edu |
Parkland College, 2400 W. Bradley Avenue, Champaign, IL 61821 |