Tuesday, 29 August 2017

C++ Basics- oops concepts

                                  c++


   To support the principles of object-oriented programming, all OOP languages
have three traits in common:

1) encapsulation,
2) polymorphism,
3) inheritance.



1)Encapsulation :=>

 Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.


  => When code and data are linked together in this fashion, an object is
created


=> Each  time you define a new type of object, you are creating a new data type


2) Polymorphism=>

    which is characterized by the phrase "one interface, multiple methods."

   In simple terms, polymorphism is the  attribute that allows one interface to control access to a general class of actions.

=>       Polymorphism helps reduce complexity by allowing the same interface to be used to access a general class of actions. It is the compiler's job to select the specific action
(i.e., method)


3)  Inheritance  =>


Inheritance is the process by which one object can acquire the properties of another object.
This is important because it supports the concept of classification.






********************************************************************

iostream


=>  there is no .h extension to the iostream. The reason is that <iostream>      is one of the new-style headers defined by Standard C++.

=>  New-style headers do not use the .h extension.

******************************************************
using namespace std;


=>    This tells the compiler to use the std namespace.

=>    Namespaces are a recent addition  to C++.

=>   A namespace creates a declarative region in which various program elements
can be placed.

=>  Namespaces help in the organization of large programs.


=>   The using  statement informs the compiler that you want to use the std namespace.

=> This is the  namespace in which the entire Standard C++ library is declared. By using the std  namespace you simplify access to the standard library.


**************************************************************************
Function overloading =>



 One way that C++ achieves polymorphism is through the use of function overloading.

In C++, two or more functions can share the same name as long as their parameter
declarations are different. In this situation, the functions that share the same name are said to be overloaded, and the process is referred to as function overloading.


************************************************************


Operator Overloading  =>

in C++, it is possible to use the << and >> operators to perform console I/O operations.

They can perform these extra operations because in the <iostream> header, these
operators are overloaded.

  When an operator is overloaded, it takes on an additional meaning relative to a certain class. However, it still retains all of its old meanings.



******************************************************************88

Constructors and Destructors



=>  C++ allows objects to initialize themselves when they are created.

=>  This automatic initialization is performed through the use of a constructor function.


=> A constructor function is a special function that is a member of a class and has the same name as that class.


=> most constructor functions will not output or input anything. They will simply perform various initializations.




 Destructor::::::




=>    An object's constructor is automatically called when the object is created. This means that it is called when the object's declaration is executed.



===>  The complement of the constructor is the destructor

=>   in many circumstances, an object will need to perform some action or actions when it is destroyed.


=> Local objects are created when their block is entered, and destroyed when the block is left. Global
objects are destroyed when the program terminates.

=> When an object is destroyed, its destructor (if it has one) is automatically called.


=>
                                                 . There are many reasons why a
destructor function may be needed. For example, an object may need to deallocate
memory that it had previously allocated or it may need to close a file that it had
opened. In C++, it is the destructor function that handles deactivation events. The
destructor has the same name as the constructor, but it is preceded by a ~.



************************************************************************

No comments:

Post a Comment