OOPortal OOPortal

C++ Class Construct  «Prev  Next»
Lesson 13

Building classes and class construct Conclusion

This module discussed some of the basic concepts of building classes in C++ and were introduced to the internal workings of the class construct. In particular you learned:
  1. How the scope resolution operator is used to define class scope
  2. How to write external member functions for a class
  3. Some basic concepts of function overloading
  4. How nested classes work
  5. The use of static and const members in a class
  6. How to use the self-referential this pointer

You define a new data type by defining a class, but before I get into the language, syntax, and programming techniques of classes, I will explain how your existing knowledge relates to the concept of object-oriented programming. Almost everything you have seen up to now has been procedural programming, which involves programming a solution in terms of fundamental data types. The essence of object-oriented programming is that you write programs in terms of objects in the domain of the problem you are trying to solve, so part of the program development process involves designing a set of types to suit the problem context. If you are writing a program to keep track of your bank account, you will probably need to have data types such as Account and Transaction. For a program to analyze baseball scores, you may have types such as Player and Team. The variables of the fundamental types do not allow you to model real-world objects (or even imaginary objects) very well. It is not possible to model a baseball player realistically in terms of just an int or double, value or any other fundamental data type. You need several values of a variety of types for any meaningful representation of a baseball player. Classes provide a solution. A class type can be
  1. a composite of variables of other types of fundamental types or
  2. of other class types.
A class can also have functions as an integral part of its definition. You could define a class type called Box that contains variables that store a length, a width, and a height to represent boxes. You could then define variables of type Box, just as you define variables of fundamental types. Each Box object would contain its own length, width and height dimensions and you could create and manipulate as many Box objects as you need in a program.

Building Classes - Quiz

Click the Quiz link below to take a multiple-choice quiz covering the topics presented in this module.
Building Classes - Quiz