CSCI 1300
Lecture Notes
10/14/97
Administrative Stuff
Administrative Stuff
Results of Quiz #2
Readings: 11.1 and 11.2 (classes), 8.1 and 8.2 (files)
Classes
Example
More on classes
Constructors and destructors
-
- Each class may have a special function called a constructor that:
-
- is called implicitly at the time that a variable of that type is declared.
- is usually used to initialize member variables.
The constructor must have the same name as the class
Each class may have a special function called a destructor that is called at the time that an object is destroyed.
Operators
It is possible to define operators for a class.
-
- Operators are defined just like functions
-
- The first parameter is implicitly the object itself. It doesn't need to be declared.
- All C++ operators can be defined for a class (+, -, =, ==, etc.).
- See the example for details.
Overloading
Any function or operator in C++ can be defined more than once as long as each definition has a different parameter list.
A function defined more than once is said to be overloaded.
The correct function to use is chosen based on the parameters passed in the function call.