- [Instructor] In C++, classes are like custom data types.
They're generally used like the fundamental types
provided by the C++ language.
In C++, classes and objects are extremely powerful,
with many features and capabilities.
This chapter will cover the basics,
which should be enough for many purposes.
For more detail, please see the companion course,
C++ Advanced Topics.
Let's start by defining some terminology.
First, we'll look at the words class and object.
The definition of a class, using the class keyword,
is the class itself.
You can then use the class to create an object.
The object is sometimes called an instance of a class.
Sometimes you'll hear the verb form instantiate
to describe the process of creating an object.
Object members are the contents of an object.
There are two types of members.
Data members are the members
that represent encapsulated data.
Data members are sometimes called properties.
Function members are the functions associated with the class
and function members are sometimes called methods.
Constructors and destructors are special function members
that are called when an object is created
or destroyed, respectively.
A constructor is called when the object is created.
There may be several constructors defined,
but only one is called for each instance of an object.
Constructors are named with the name of the class.
The destructor is called when the object is destroyed.
Only one destructor may be defined with each class.
The destructor is named with a tilde character
followed by the name of the class.
C++ classes allow you to create fully realized types
that work exactly how you want them to.
Using C++ classes you may create constructors
for variety of different usages,
allocate and deallocate memory appropriately
so that your objects run smoothly,
overload operators so that your objects
can use those operators intelligently,
create conversion operators so that your objects behave
as you expect them to in different contexts.
In the remainder of this chapter,
I'll give you the basics of creating and using objects.
For more detail, including class inheritance, polymorphism,
see the companion course C++ Advanced Topics.