Lesson 1
Inside a class in C++
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:
By default, all members of a class declared with the class keyword have private access for all its members.
- How the scope resolution operator is used to define class scope
- How to write external member functions for a class
- Some basic concepts of function overloading
- How nested classes work
- The use of static and const members in a class
- How to use the self-referential this pointer
Therefore, any member that is declared before one other class specifier automatically has private access.
For example:
class CRectangle {
int x, y;
public:
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:
This class contains four members:
- two data members of type int (member x and member y) with private access (because private is the default access level) and
- two member functions with public access: setValues() and area(),