Classes
Classes
- Classes are the building blocks of an object oriented program
- Classes extend structs by encapsulating data members along with the
functions that operate on these data members
- Thus, a Class definition specifies its data members as well as its
member
functions
- Variables that belong to classes are referred to as "objects".
Objects are
concrete "instances" of a class
- Classes are "instantiated" by defining objects. This results in
memory
being allocated to store the object
- Access to data members and member functions is accomplished using the
. (dot) and -> operators
- The access specifier defines the degree of accessibility of individual
class
members
- public members may be accessed by member functions of same
object,
and by functions outside the scope of the class
- protected members may be accessed only by member functions of
the
same object or by member functions of objects belonging to subclasses of
the
class
- private members may only be accessed by member functions of
the
same object
- When member functions of an object are invoked to operate on data
members, it is not necessary to specify the object name of the data member
being operated
on. In other words, it is not necessary to use the .
(dot) operator
- Example...
- Class objects can be handled using pointers, similar to built-in data
types. Example...
Back to Previous Page
Document:
Local Date:
Last Modified On: