Click here to Skip to main content
15,923,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: help Pin
Cedric Moonen2-Nov-06 4:56
Cedric Moonen2-Nov-06 4:56 
AnswerRe: help Pin
normanS2-Nov-06 6:37
normanS2-Nov-06 6:37 
Questionhelp Pin
Kiethnt2-Nov-06 4:11
Kiethnt2-Nov-06 4:11 
QuestionConvert Time to CString? Pin
bosfan2-Nov-06 4:05
bosfan2-Nov-06 4:05 
AnswerRe: Convert Time to CString? Pin
bosfan2-Nov-06 4:16
bosfan2-Nov-06 4:16 
GeneralRe: Convert Time to CString? Pin
Niklas L2-Nov-06 21:42
Niklas L2-Nov-06 21:42 
QuestionDerived classes and over riding Pin
Waldermort2-Nov-06 3:41
Waldermort2-Nov-06 3:41 
AnswerRe: Derived classes and over riding Pin
benjymous2-Nov-06 4:22
benjymous2-Nov-06 4:22 
It all depends on whether you use the base pointer, or the derived pointer

class CBase1
{
  virtual void Message() { cout << "CBase!1"; }
}

class CDerived1 : public CBase1
{
  virtual void Message() { cout << "CDerived1!"; }
}

class CBase2
{
  void Message() { cout << "CBase2!"; }
}

class CDerived2 : public CBase2
{
  void Message() { cout << "CDerived2!"; }
}



CBase1* obj1 = new CBase1();
obj1->Message(); // outputs "CBase1!"

CBase1* obj2 = new CDerived1();
obj2->Message(); // outputs "CDerived1!" 

CDerived1* obj3 = new CDerived1();
obj3->Message(); // outputs "CDerived1!" 

CBase2* obj4 = new CBase2();
obj4->Message(); // outputs "CBase2!"

CBase2* obj5 = new CDerived2();
obj5->Message(); // outputs "CBase2!" 

CDerived2* obj6 = new CDerived2()
obj6->Message(); // outputs "Derived2!"



So if you have a complex class hierarchy, with lots of objects derived from a single base class, and you want to store a vector of objects, and have each perform their unique operations, you'll need to use virtual, since your vector doesn't know what type the objects are, it just thinks of them all as base class objects




--
Help me! I'm turning into a grapefruit!
Buzzwords!

GeneralRe: Derived classes and over riding Pin
Waldermort2-Nov-06 4:55
Waldermort2-Nov-06 4:55 
AnswerRe: Derived classes and over riding Pin
Mark Salsbery2-Nov-06 8:15
Mark Salsbery2-Nov-06 8:15 
GeneralRe: Derived classes and over riding Pin
Waldermort2-Nov-06 9:43
Waldermort2-Nov-06 9:43 
AnswerRe: Derived classes and over riding Pin
Michael Dunn2-Nov-06 9:12
sitebuilderMichael Dunn2-Nov-06 9:12 
Questionassigning string to char Pin
Tara142-Nov-06 3:23
Tara142-Nov-06 3:23 
AnswerRe: assigning string to char Pin
David Crow2-Nov-06 3:28
David Crow2-Nov-06 3:28 
GeneralRe: assigning string to char Pin
Tara142-Nov-06 4:38
Tara142-Nov-06 4:38 
AnswerRe: assigning string to char Pin
bosfan2-Nov-06 4:23
bosfan2-Nov-06 4:23 
QuestionAccess PoolNonPagedBytes Pin
suresh_suryavanshi2-Nov-06 3:15
suresh_suryavanshi2-Nov-06 3:15 
AnswerRe: Access PoolNonPagedBytes Pin
Mark Salsbery2-Nov-06 8:21
Mark Salsbery2-Nov-06 8:21 
GeneralRe: Access PoolNonPagedBytes Pin
suresh_suryavanshi5-Nov-06 18:26
suresh_suryavanshi5-Nov-06 18:26 
QuestionNot responding in task bar icon Pin
MikeRT2-Nov-06 2:59
MikeRT2-Nov-06 2:59 
AnswerRe: Not responding in task bar icon Pin
Mark Salsbery2-Nov-06 8:24
Mark Salsbery2-Nov-06 8:24 
GeneralRe: Not responding in task bar icon Pin
MikeRT2-Nov-06 17:22
MikeRT2-Nov-06 17:22 
GeneralRe: Not responding in task bar icon Pin
Mark Salsbery2-Nov-06 20:06
Mark Salsbery2-Nov-06 20:06 
QuestionMulti line support for static control Pin
see me2-Nov-06 2:58
see me2-Nov-06 2:58 
AnswerRe: Multi line support for static control Pin
_AnsHUMAN_ 2-Nov-06 3:06
_AnsHUMAN_ 2-Nov-06 3:06 

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.