C++ Class Data Member Fields

Introduction

A class can have a set of some data in it.

These are called member fields.

Let us add one member field to our class and make it of type char:

class MyClass 
{ 
    char c; 
}; 

Now our class has one data member field of type char called c.

Let us now add two more fields of type int and double:

class MyClass 
{ 
    char c; 
    int x; 
    double d; 
}; 

Now our class has three member fields, and each member field has its name.




PreviousNext

Related