C++ Class Attributes & Methods
Class Attributes & Methods
Class attributes and methods are variables and functions that are defined inside the class. They are also known as class members altogether.
Consider an example below to understand what class attributes are
A class named Employee is built and two members, eId and eName are defined inside the class. These two members are variables and are known as class attributes. Now, an object named Maxon is defined in the main. Maxon can access these attributes using the dot operator. But they are not accessible to Maxon unless they are made public.
Output
Class methods are nothing but functions that are defined in a class or belong to a class. Methods belonging to a class are accessed by their objects in the same way that they access attributes. Functions can be defined in two ways so that they belong to a class.
Defining inside the class
An example that demonstrates defining functions inside classes is
Defining outside the class
Although, a function can be defined outside the class, it needs to be declared inside. Later, we can use the scope resolution operator (::) to define the function outside.
An example that demonstrates defining functions outside classes is