Key Concepts

Review core concepts you need to learn to master this subject

C++ class destructor

For a C++ class, a destructor is a special method that handles object destruction, generally focused on preventing memory leaks. Class destructors don’t take arguments as input and their name is always preceded by a tilde (~).

C++ class members

A C++ class is comprised of class members. Class attributes, also known as member data, consist of information about an instance of the class. Class methods, also known as member functions, are functions that can be used with an instance of the class. If a class member is static, it is shared by all instances of the class. Also, no instance is required in order to access the value of a static member.

C++ class constructor

For a C++ class, a constructor is a special kind of method that enables control regarding how the objects of a class should be created. Different class constructors can be specified for the same class, but each constructor signature must be unique.

C++ class instances

In C++, an object is an instance of a class that encapsulates data and functionality pertaining to that data. Only non abstract classes can be instanced. If a class is abstract it defines the needed behavior to its derivative classes.

C++ access control operators

C++ classes have access control operators that designate the scope of class members: public and private. Public members are accessible everywhere; private members can only be accessed from within the same instance of the class or from friends classes. If a class member is protected, it can be accessed by friends and inherited classes.

Classes and Objects
Lesson 1 of 1
  1. 1
    So far, we’ve used several data types, including int, double, std::string, and bool. When we work with int or std::string, we can create variables with certain properties and methods specific to th…
  2. 2
    An empty class is pretty useless. Classes are designed to bring together related information and functionality — time to add stuff inside! Components of a class are called class members. Just l…
  3. 3
    Now that you have a class, let’s create some objects! To refresh your memory, an object is an instance of a class, which encapsulates data and functionality pertaining to that data. To create (or …
  4. 4
    Let’s circle back to that public keyword. What was that about? By default, everything in a class is private, meaning class members are limited to the scope of the class. This makes it easier to ke…
  5. 5
    Is there a way to give an object some data right when it gets created? We’re so glad you asked! A constructor is a special kind of method that lets you decide how the objects of a class get crea…
  6. 6
    So far, you’ve learned how to create and use objects. But there’s another part of the object lifecycle we need to cover: how to destroy them! Muahahaha. It’s actually far less nefarious than it so…
  7. 7
    Hooray! You’ve learned the basics of classes and objects in C++: - Classes are user-defined types. - Objects are instances of classes. - Class members are the data attributes and functions inside o…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo