Access Modifiers

In this lesson, you will learn about the private, public and protected members.

We'll cover the following

In C++, we can impose access restrictions on different data members and member functions. The restrictions are specified through access modifiers. Access modifiers are tags we can associate with each member to define which parts of the program can access it directly.

There are three types of access modifiers. Let’s take a look at them one by one.

Private

A private member cannot be accessed directly from outside the class. The aim is to keep it hidden from the users and other classes. It is a popular practice to keep the data members private since we do not want anyone manipulating our data directly. By default, all declared members are private in C++. However, we can also make members private using the private: heading.

Get hands-on with 1400+ tech skills courses.