Click here to Skip to main content
15,898,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with polymorphism Pin
ng kok chuan2-Mar-05 17:23
ng kok chuan2-Mar-05 17:23 
GeneralRe: Problem with polymorphism Pin
Ryan Binns2-Mar-05 22:27
Ryan Binns2-Mar-05 22:27 
GeneralRe: Problem with polymorphism Pin
ng kok chuan3-Mar-05 14:31
ng kok chuan3-Mar-05 14:31 
GeneralRe: Problem with polymorphism Pin
David Crow3-Mar-05 2:35
David Crow3-Mar-05 2:35 
GeneralRe: Problem with polymorphism Pin
ng kok chuan2-Mar-05 20:01
ng kok chuan2-Mar-05 20:01 
GeneralRe: Problem with polymorphism Pin
Cedric Moonen2-Mar-05 20:36
Cedric Moonen2-Mar-05 20:36 
GeneralRe: Problem with polymorphism Pin
Steen Krogsgaard2-Mar-05 21:40
Steen Krogsgaard2-Mar-05 21:40 
GeneralRe: Problem with polymorphism Pin
Alton Williams5-Mar-05 4:03
Alton Williams5-Mar-05 4:03 
ng kok chuan wrote:
pointer[0] = *(new Base);<br />
pointer[1] = *(new Derive1);<br />
pointer[2] = *(new Derive2); and so on...

This what is known a late binding

ng kok chuan wrote:
the type of classes are created correctly when the constructors are called. however, when i tried to access the pointers again later in my program, the program only treats each pointer as Base and no longer as any derived classes. thus polymorphism cannot work at all... this is crucial to me as i have several classes that's supposed to belong to the vector of pointers. if i use a simple array polymorphism works. but i need the vector.

How about putting the virtual before the name of the function (in the base class)


ng kok chuan wrote:
vector < Base* > pointer)<br />
pointer[0] = *(new Base);



doesn't make sense
Surely, it shold be

pointer[0] = new Base;

Anyway, I got a sample app to give you an idea. If you e-mail I'll gladly send it to you.

Happy programming
Alton
GeneralC++ Wrapper for libCURL Pin
a_diwakar2-Mar-05 17:02
a_diwakar2-Mar-05 17:02 
Questionhow to use a video codec to compress avi file Pin
Mohsen Saad2-Mar-05 15:22
Mohsen Saad2-Mar-05 15:22 
GeneralText to matrix conversion Pin
SeanSheehan2-Mar-05 14:32
SeanSheehan2-Mar-05 14:32 
GeneralSmall executables Pin
Verolix2-Mar-05 13:49
Verolix2-Mar-05 13:49 
GeneralRe: Small executables Pin
ThatsAlok2-Mar-05 18:00
ThatsAlok2-Mar-05 18:00 
Generalresizing workarea Pin
ahto1112-Mar-05 12:07
ahto1112-Mar-05 12:07 
GeneralC++ library Pin
Ahmed Adel2-Mar-05 11:33
Ahmed Adel2-Mar-05 11:33 
GeneralRe: C++ library Pin
ThatsAlok2-Mar-05 18:10
ThatsAlok2-Mar-05 18:10 
QuestionError? Pin
Larsson2-Mar-05 10:53
Larsson2-Mar-05 10:53 
AnswerRe: Error? Pin
Ravi Bhavnani2-Mar-05 10:55
professionalRavi Bhavnani2-Mar-05 10:55 
GeneralRe: Error? Pin
Larsson2-Mar-05 10:57
Larsson2-Mar-05 10:57 
GeneralRe: Error? Pin
Ravi Bhavnani2-Mar-05 11:01
professionalRavi Bhavnani2-Mar-05 11:01 
GeneralRe: Error? Pin
Larsson2-Mar-05 11:06
Larsson2-Mar-05 11:06 
GeneralRe: Error? Pin
Christian Graus2-Mar-05 11:07
protectorChristian Graus2-Mar-05 11:07 
GeneralRe: Error? Pin
Larsson2-Mar-05 11:10
Larsson2-Mar-05 11:10 
GeneralRe: Error? Pin
Christian Graus2-Mar-05 11:13
protectorChristian Graus2-Mar-05 11:13 
GeneralRe: Error? Pin
David Crow3-Mar-05 2:42
David Crow3-Mar-05 2:42 

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.