• Inline functions
  • Function default arguments
  • Function overloading
  • Pass by value


Classes and Objects  in C++


Class is a data type or user defined data type.

It is a collection of members, these members are 2 types.

Data members

Member functions

In object oriented application development data is represent in the form of object


Difference between class & structure


class in c++ Structure in ‘C’
It is a collection of variables and functionsstructure is a collection of variables
Contents is private, protected or publicContents is public / global
It provide security for dataIt does not provide security for data
It support polymorphism and inheritanceIt does not support polymorphism and inheritance



Syntax of class in C++

class  class-type-name


private :



public :


member functions;



What is data member ?

Variable declared inside class is called data member

Data member define state of the object or value hold by object.


Member function in C++

Function defined inside a class is called member function

Binding data members with member function inside a class called as

Member function define behavior of object or operation performed on the object

Private, public and protected are called as access specifier.

Default members of class are private

Default members of structure are global/ public


Access specifier/ access neighbours

Access specifier define visibility on accessibility of members declared within class.

C++ provide 3 access specifiers

  1. private
  2. protected
  3. public



Default members of class are private

Private member are accessible within class or members of the same class

Private members are not accessible within non members on members of other classes.





Data hiding in object oriented is achieved by declaring data members within class as private


Protected member access by members of same class and derived class

Protected members cannot access by non members and members of other classes.








These  members access by members of some class, derived class, non members and members of other classes.





Summary of Access Specifiers


 with in classNon membersMember of derived classMember of Other class



Object in C++

  • It is a instance of class
  • A variable of type class is called object
  • On creation of object memory is allocated for data members of class.


Class –name object –name, object-name,….

class defined structure of object


Program (Write a program to find area of triangular)

# include <iostream.h>                   [ writing a class within main- local

class triangle                                             classes & vice versa]


private :

float base, height;                 // data members

public :

void read()


cout<<”\n input base height”;



void find area ()


float area=0.5*base*height;



Size of the class is equal to some of data member size

On creation of object memory is allocated for data members of class but not member functions

Member functions operators on one or more than one object.