CLASS DECLARATION

When writing C++ program you need to define a Class before you can use it in C++ main program. So we can say that in C++ terminology the class is nothing else than special type of data which needs to be declared before we can use it. Declaration of class consists of two main parts:
·         First part: Heading and
·         Second part: body.
Heading of a class consists of the keyword class after which you need to define the name of a class and the body of a class which follows after heading is bounded by a pair of curly brackets. To visualize a structure of a class let’s see the following example:
class class_name /*This is the class heading*/
{
       /*This is the class body*/
};
For example let’s define the class Car.
class Car {
      
};
Important to remember!!!
The declaration of class always ends with the sign ;
A name of the class is identifier which must be unique in certain name scope. Objects of the class can be constructed by specifying the class name followed by the list the names of objects separated by commas:
Car Ferrari, Porche, Mercedes, BMW;
In this example four objects are defined that is Ferrari, Porche, Mercedes and BMW of class Car. As we see, the declaration of user defined objects in no way is no different from declarations of built-in types. Here as a type listed in the name of the class whose image and likeness of the object created.
The body of the class may contain:
·         Data members,
·         Functional members,
·         Declaration of nested classes and

·         Specifications of access rights. 
Share on Google Plus