blue-print
of an object. It does not define any data directly but the class represents two important functions of an object such as:class
The identifier used specifies the class name. Class body is given in {}. The class definition ends with a semicolon ;.
Member Function
. It is possible to access any of the object and object members present in CPP classes in which the member function is defined. A member function can be declared and used in two ways.Inline Functions
". Even if the inline specifier is not specified, it is considered as inside class function.
[c]
class John_marks
{
public:
int maths_marks;
int science_marks;
int social_marks;
int getAverage(void); // inside class member function
{
return maths_marks + science_marks + social_marks;
}
};[/c]
These are used outside of the class with the help of scope resolution operator::. The operator is placed after the name of class.
friend function
is defined outside that class scope but has the right to access all private and protected members of the class.
The member functions of C++ classes will have the this pointer
to point to the address of class objects.
Static member functions
are independent of objects of the class and can be called without objects also