next up previous contents index
Next: References and Function Arguments Up: More About C++ Previous: Mathematical Functions   Contents   Index

Basics of Classes

Unlike C, C++ supports ``object-oriented programming''. In a nutshell, a class is an abstraction in computer code of some concept, such as a point, a sphere, a mapping that can be plotted, or a camera. Implementationally, a class consists of members (named data elements) and member functions (functions that belong to the class and have free access to members). The idea is to encapsulate objects and the operations that make sense for them in a single logical entity. In simple programming, classes may be treated like built-in types.

C++ classes enforce access permissions on their members, protecting data from being manipulated except in controlled ways. A class's member functions (and ``public'' members) constitute its user interface. The concept of class separates logical aspects of a data type from a particular implementation.

Each ``instantiation'' of a class has its own member functions. A member function therefore knows ``which object'' it was called on, and the call syntax differs from standard function calls:

  circle C1(P(1,0), 1.5); // circle of given center and radius
  C1.draw();              // member function circle::draw();
Naturally, this call draws the circle C1.

A few short paragraphs cannot do more than scratch the surface of classes and object-oriented programming. Please consult a book, such as Stroustrup [4], for details.


next up previous contents index
Next: References and Function Arguments Up: More About C++ Previous: Mathematical Functions   Contents   Index
Andrew D. Hwang 2004-09-04