Click here to Skip to main content
15,900,973 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Conneting to a computer using socket Pin
CPallini8-Dec-09 22:13
mveCPallini8-Dec-09 22:13 
GeneralRe: Conneting to a computer using socket Pin
Moak12-Dec-09 4:27
Moak12-Dec-09 4:27 
AnswerRe: Conneting to a computer using socket Pin
Moak9-Dec-09 2:31
Moak9-Dec-09 2:31 
GeneralRe: Conneting to a computer using socket Pin
bubuzzz10-Dec-09 21:51
bubuzzz10-Dec-09 21:51 
QuestionGenerating Tables in WORD Pin
Chandrasekharan P8-Dec-09 20:15
Chandrasekharan P8-Dec-09 20:15 
AnswerRe: Generating Tables in WORD Pin
CPallini8-Dec-09 21:05
mveCPallini8-Dec-09 21:05 
QuestionCopy File Folder Message Pin
NVCprog8-Dec-09 19:37
NVCprog8-Dec-09 19:37 
QuestionRe: Copy File Folder Message Pin
sashoalm8-Dec-09 21:14
sashoalm8-Dec-09 21:14 
AnswerRe: Copy File Folder Message Pin
Madhu Nair8-Dec-09 21:40
Madhu Nair8-Dec-09 21:40 
AnswerRe: Copy File Folder Message Pin
Rajesh R Subramanian8-Dec-09 22:37
professionalRajesh R Subramanian8-Dec-09 22:37 
GeneralRe: Copy File Folder Message Pin
NVCprog9-Dec-09 17:13
NVCprog9-Dec-09 17:13 
GeneralRe: Copy File Folder Message Pin
NVCprog11-Dec-09 18:56
NVCprog11-Dec-09 18:56 
QuestionHow to get exe Pin
jannathali8-Dec-09 19:17
jannathali8-Dec-09 19:17 
AnswerRe: How to get exe Pin
Cedric Moonen8-Dec-09 20:28
Cedric Moonen8-Dec-09 20:28 
Questionhow does an uninstall exe delete itself? Pin
includeh108-Dec-09 19:02
includeh108-Dec-09 19:02 
AnswerRe: how does an uninstall exe delete itself? Pin
o m n i8-Dec-09 20:47
o m n i8-Dec-09 20:47 
GeneralRe: how does an uninstall exe delete itself? Pin
includeh108-Dec-09 21:36
includeh108-Dec-09 21:36 
GeneralRe: how does an uninstall exe delete itself? Pin
David Crow9-Dec-09 2:17
David Crow9-Dec-09 2:17 
AnswerRe: how does an uninstall exe delete itself? Pin
David Crow9-Dec-09 2:19
David Crow9-Dec-09 2:19 
QuestionInheritance!!! Pin
Nilesh Hamane8-Dec-09 18:58
Nilesh Hamane8-Dec-09 18:58 
AnswerRe: Inheritance!!! Pin
Cedric Moonen8-Dec-09 20:26
Cedric Moonen8-Dec-09 20:26 
Before answering your question, I think there should be a small modification in your code of the Cpolygon class: you should have a virtual area function:
class Cpolygon
{
...
virtual int area() = 0;
};   


Otherwise those two lines won't compile:
cout<<Poly1->area()<<endl;
 cout<<Poly2->area()<<endl;


First question: you have two pointers to a base class and you make them point to derived classes. This would be more or less similar as this:
Cpolygon *Poly1 = new Crectangle();
 Cpolygon *Poly2 =new Ctriangle();


Which is seen more often.

In fact the whole purpose of this code is to show you the use of polymorphism (I suggest you google for it to have a lot more examples). The base principle is that you can manipulate objects of different types (Crectangle and Ctriangle) exactly the same way: they all implement a known interface (Cpolygon). This way, you can store them all in a container and you don't need to know which exact type you are manipulating. Each time you call a virtual function (like area()), it will be "redirected" to the correct type. This is one of the most basic and fundamental principle of object oriented programming.

Cédric Moonen
Software developer

Charting control [v2.0]
OpenGL game tutorial in C++

AnswerRe: Inheritance!!! Pin
cheetach8-Dec-09 20:28
cheetach8-Dec-09 20:28 
QuestionCombination C and OpenGL: Making a loop to draw circles [modified] Pin
Chidori-chan8-Dec-09 18:46
Chidori-chan8-Dec-09 18:46 
AnswerRe: Combination C and OpenGL: Making a loop to draw circles Pin
LunaticFringe8-Dec-09 19:43
LunaticFringe8-Dec-09 19:43 
GeneralRe: Combination C and OpenGL: Making a loop to draw circles Pin
Chidori-chan8-Dec-09 20:35
Chidori-chan8-Dec-09 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.