Wednesday 7 March 2018

Constructors and Destructors in C++




Constructors

Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object.

class A
{
 int x;
 public:
 A();  //Constructor
};

Saturday 5 August 2017

Function Overloading in CPP


Function Overloading:

If any class have multiple functions with same names but different parameters then they are said to be overloaded. Function overloading allows you to use the same name for different functions, to perform, either same or different functions in the same class.

Function overloading is usually used to enhance the readability of the program. If you have to perform one single operation but with different number or types of arguments, then you can simply overload the function.



Wednesday 12 July 2017

Types of Member Functions


Types of Member Functions:

We already know what member functions are and what they do. Now let’s study some special member functions present in the class. Following are different types of Member functions,

1.     Simple functions

2.    Static functions

3.    Const functions

4.    Inline functions

5.    Friend functions


Member Functions in Classes


Member Functions in Classes:

Member functions are the functions, which have their declaration inside the class definition and works on the data members of the class. The definition of member functions can be inside or outside the definition of class.

If the member function is defined inside the class definition it can be defined directly, but if its defined outside the class, then we have to use the scope resolution :: operator along with class name along with function name.

Accessing Data Members of Class


Accessing Data Members of Class:

Accessing a data member depends solely on the access control of that data member. If it’s public, then the data member can be easily accessed using the direct member access (.) operator with the object of that class.