Class Data Members

This lesson will go into the details of the data members of a class.

We’ve learned that the data members contain all the information we store in a class. All the data members have to be defined at compile time.

Data members should be defined as private.

Data Types of Member Variables

C++ gives us a lot of freedom in selecting the data type of a data member. We can choose any of the in-built types such as int, double etc. Arrays, vectors, and pointers can also be used. The object of our custom class could have a number of arrays and variables! pretty cool right?

Here’s an example of a Student class and its data members:

Get hands-on with 1200+ tech skills courses.