Click here to Skip to main content
15,921,793 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralGetUserName() fails in ATL COM object Pin
bryces2-Dec-03 19:47
bryces2-Dec-03 19:47 
GeneralRe: GetUserName() fails in ATL COM object Pin
Michael P Butler2-Dec-03 20:20
Michael P Butler2-Dec-03 20:20 
GeneralRe: GetUserName() fails in ATL COM object Pin
bryces2-Dec-03 21:09
bryces2-Dec-03 21:09 
GeneralRe: GetUserName() fails in ATL COM object Pin
BaldwinMartin2-Dec-03 23:21
BaldwinMartin2-Dec-03 23:21 
Generalgripper in top left corner of resiable combo box Pin
Suneet Chandok2-Dec-03 19:08
Suneet Chandok2-Dec-03 19:08 
GeneralDisplay a MessageBox in CDialog::OnActivate() Pin
Chris Ormerod2-Dec-03 18:16
Chris Ormerod2-Dec-03 18:16 
GeneralRe: Display a MessageBox in CDialog::OnActivate() Pin
Chris Ormerod2-Dec-03 18:22
Chris Ormerod2-Dec-03 18:22 
GeneralQuestion regarding inheritance Pin
lsanil2-Dec-03 17:24
lsanil2-Dec-03 17:24 
Hi All,

I have a question on the following code.

class ClassA<br />
{<br />
   virtual void TestA()=0;<br />
};<br />
<br />
class ClassB: public ClassA<br />
{<br />
  virtual void TestA();<br />
  ClassB();<br />
  virtual ~ClassB();<br />
  void PrintB();<br />
};<br />
<br />
void ClassB::TestA()<br />
{<br />
  cout << "TestA is Called from ClassB"<<endl;<br />
  return;<br />
}<br />
<br />
void ClassB::PrintB()<br />
{<br />
  cout << "PrintB is called" << endl;<br />
  return;<br />
}<br />
<br />
class ClassC: public ClassA<br />
{<br />
  virtual void TestA();<br />
  ClassC();<br />
  virtual ~ClassC();<br />
  void PrintC();<br />
};<br />
<br />
void ClassC::TestA()<br />
{<br />
  cout << "TestA is Called from ClassC" << endl;<br />
  return;<br />
}<br />
<br />
void ClassC::PrintC()<br />
{<br />
  cout << "PrintC is called" << endl;<br />
  return;<br />
}<br />
<br />
ClassA *pB;<br />
ClassA *pC;<br />
<br />
pB = new ClassB();<br />
pC = new ClassC();<br />
<br />
pB->TestA(); //works fine<br />
pC->TestC(); //works fine<br />
<br />
//Compilation Errors<br />
pB->PrintB();<br />
pC->PrintC();


In the above code, I am getting compilation errors as commented in the code. Is there anyway of calling methods of inherited class with a pointer to the base class?

My requirement is to call appropriate inherited class at runtime basing upon the user input with a single pointer to a base class. i.e

ClassA *pGeneric;<br />
if(user_input == 1)<br />
 pGeneric = new ClassB()<br />
else<br />
 pGeneric = new ClassC();


This works when the both inherited classes have the same methods but fails if inherited class an extra method. Is there any way to call one of the inherited classes during runtime with a SINGLE pointer to base class?

First of all, I want to know is it possible to do in C++? If it is possible, please suggest me the approach to take.
Please help me out. Please suggest me any other methods that provide the same functionality.

Thanks in Advance,
Anil
GeneralRe: Question regarding inheritance Pin
Christian Graus2-Dec-03 17:29
protectorChristian Graus2-Dec-03 17:29 
GeneralRe: Question regarding inheritance Pin
lsanil2-Dec-03 18:57
lsanil2-Dec-03 18:57 
GeneralRe: Question regarding inheritance Pin
lsanil2-Dec-03 19:05
lsanil2-Dec-03 19:05 
QuestionCFormView: adding a CHeaderCtrl? Pin
ckorda2-Dec-03 16:48
ckorda2-Dec-03 16:48 
AnswerRe: CFormView: adding a CHeaderCtrl? Pin
Monty22-Dec-03 19:09
Monty22-Dec-03 19:09 
GeneralRe: CFormView: adding a CHeaderCtrl? Pin
ckorda4-Dec-03 11:43
ckorda4-Dec-03 11:43 
GeneralRe: CFormView: adding a CHeaderCtrl? Pin
Monty25-Dec-03 20:28
Monty25-Dec-03 20:28 
GeneralArrows keys Pin
Gagnon Claude2-Dec-03 16:00
Gagnon Claude2-Dec-03 16:00 
GeneralRe: Arrows keys Pin
Antti Keskinen3-Dec-03 3:07
Antti Keskinen3-Dec-03 3:07 
Generalabout record voice Pin
yingkou2-Dec-03 15:39
yingkou2-Dec-03 15:39 
GeneralRe: about record voice Pin
Peter Molnar3-Dec-03 14:45
Peter Molnar3-Dec-03 14:45 
Generalproject problem Pin
coda_x2-Dec-03 15:13
coda_x2-Dec-03 15:13 
GeneralRe: project problem Pin
Terry O'Nolley2-Dec-03 15:39
Terry O'Nolley2-Dec-03 15:39 
GeneralRe: project problem Pin
coda_x2-Dec-03 16:46
coda_x2-Dec-03 16:46 
Generalextracting clip from an avi or any other file Pin
hina_askh2-Dec-03 14:55
hina_askh2-Dec-03 14:55 
GeneralMACROS. Pin
WREY2-Dec-03 14:38
WREY2-Dec-03 14:38 
GeneralRe: MACROS. Pin
Christian Graus2-Dec-03 17:33
protectorChristian Graus2-Dec-03 17:33 

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.