Building C++ Classes  «Prev  Next»
Lesson 1

Introduction to C++ Class Construct

This module explores some of the basic concepts of building classes in C++ and introduces you to the internal workings of the class construct.
The following will be discussed in this module:
  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
At the end of the module, you will be given the opportunity to take a quiz covering these topics.
By default, all members of a class declared with the class keyword have private access for all its members.
Therefore, any member that is declared before one other class specifier automatically has private access.
For example:

 class CRectangle {
    int x, y;
    void setValues (int,int);
    int area (void);
  } rect;
Declares a class called CRectangle and an object of this class called rect.
This class contains four members:
  1. two data members of type int (member x and member y) with private access (because private is the default access level) and
  2. two member functions with public access: setValues() and area(),
of which for now we have only included their declaration, not their definition.