C++: Classes & Objects- 1

Structures in C++:

it provides a facility to hide the data which is one of the main percepts of OOP.

It also supports Inheritance, a mechanism  by which one type can inherit characteristics from other types.

It can have both variables and functions as members.
Specifying a Class:

A class is a way to bind the data and its associated functions together.

When defining a class, we are creating a new abstract data type that can be treated like any other built-in data type.

The general form of class declaration is:

    class class_name{

                    variable declaration;
                    function declaration;
                    variable declaration;
                    function declaration;

The data hiding(using private declaration) is the key feature of Object Oriented Programming.

By default, the members of a class are private.

The variables declared inside the class are known as data members and the functions are known as member functions.

Only the member functions can have access to the private data members and private functions.

The binding of data and functions together into a single class type variable is known as encapsulation.
Data cannot be accessed by any function that is not a member of the class.

Creating Objects:

class_name object_name; //memory for object is created

Accessing Class Members:

object_name.function_name(actual arguments);

Defining Member Functions:

Outside the class definition

    return-type class-name :: function-name(argument declaration){
                  Function body

A member function can call another member function directly, without using dot operator.

Inside the class definition

When a function is defined inside a class, it is treated as an inline function.

Making an outside function inline:

     class item {
               void getdata(int a, float b); //declaration

    inline void item:: getdata(int a, float b)//definition

                 < Happy Coding >


In Association with Amazon.in