Section 10.6 Member versus Nonmember Functions
(skim this section)
Class:
- A data type that combines data and functions for
operating on the data.
- Example: string is a class.
Object:
- A member/instance of the class.
- Example: string aWord; //aWord is an object, string is the class.
Classes have data and functions:
- aWord ="Fred"; //the data is "Fred"
- aWord.length() //length is a function that can be
applied to a member of the class.
- Notation: object_name.member_function()
So what?
- Convenience of bundling related data and functions that operate on it.
- Abstraction: lift the features of strings above the technicalities of
how they are implemented.
- An essential component of large system development.
- Examples of possible objects:
- A matrix
- A student record
- A radar interface
ifstream and ofstream as classes
- The classes:
- ifstream: used for input from a file.
- ofstream: used for output to a file.
- The object: a file stream variable.
- Member functions: .open, .close, .getline.
E.g.
ofstream fout;
fout.open("out.txt");