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.

Defining Class and Declaring Objects


Defining Class and Declaring Objects:

When we define any class, we are not defining any data, we just define a structure or a blueprint, as to what the object of that class type will contain and what operations can be performed on that object.

Access Specifiers in C++


Access Control in Classes:

Now before studying how to define class and its objects, let’s first quickly learn what access specifiers are.

Access specifiers in C++ class defines the access control rules. C++ has 3 new keywords introduced, namely,

1.     Public

2.    Private

3.    Protected

Classes and Objects in CPP


Introduction to Classes and Objects:

The classes are the most important feature of C++ that leads to Object Oriented programming. Class is a user defined data type, which holds its own data members and member functions, which can be accessed and used by creating instance of that class.

The variables inside class definition are called as data members and the functions are called member functions.