E Balaguruswamy mentions in his famous book object oriented programming with c++ "C++ is going to replace the C language in near future". It is an important thing to all embedded C developers. So it is better to learn C++ quickly.
A good c programmer can learn C++ in only one week!. This I can guarantee you all because i achieved it with the same amount of time :)
One main thing in OOP is, it helps to design the program based on the real life entities. We can easily extract the real time features to the design using the concepts such as
1) Polymorphism - one name multiple forms
2) Abstractions - Provide only the necessary information
3) Encapsulation- Wrapping up of Data and function together
4)Data hiding- Hide the unnecessary information based to safeguard the data
5)Inheritance- Deriving the features from already existing one
For example if want to write program based on line. Then we need to create point as it is basic necessity.
So line inherits the properties of the point also. So we can make point as base class and line as derived class.
Please find the appended c++ program which will helps to understand inheritance clearly.
/******************************************************************************************************
;All rights reserved -embeddedhobby.blogspot. com
;
;A C++ program written to understand OOP concepts 18-09-2011
;Author: eguru
; Inheritance
;Constructors
;overloading
;******************************************************************************************************/
#include<iostream.h>
class point
{
int x; // x coordinate
int y; // y coordinate
public:
point(int x1, int y1) // parametrized constructor
{
x =x1;
y =y1;
}
point() // Non parametrised constructor
{
x =0;
y =0;
}
void PutData(void); // function to display the point
};
class line : public point // line is class which inherits the properties of the derived class.
{
point point1,point2; // point is base class
public:
void DisplayLength(void);
line (int x1,int y1,int x2, int y2) : point1(x1, y1), point2(x2, y2) // constructor list
{
cout<< " line initialised";
}
line():point1(), point2()
{
cout << " line is initialised zero";
}
};
/******************************************************************************************************
;All rights reserved - embeddedhobby.blogspot.com
;******************************************************************************************************/
void line::DisplayLength(void)
{
point1.PutData();
point2.PutData();
}
void point::PutData(void)
{
cout << "\n origin x="<<x;
cout << "\n origin y= "<<y;
}
main()
{
cout << "WellCome to C++";
cout<<" Input 1 to display line";
int x;
cin >>x;
line straight;
switch(x)
{
case 1:
cout<< " Line coordinates are as follows" ;
straight.DisplayLength();
break;
case 2:
cout<< " Add code for your experiment" ;
break;
default:
cout << " Bye Bye ";
break;
}
point ORG;
cin >>x;
return 0;
}
For any further information please feel free to mail at contact_ehobby@gmail.com -eguru