derived class functions, with dif arg lists

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have several Classes that derive from a common Base Class
Each of these Classes Has a Differnt Version of a Function with the Same
Short name, but different Long Name.

See Bellow:

// Base Class
class CBase
{
void DoStuff(CBase* other);
}

//Derived Class 1
class CDerived1: public CBase
{
void DoStuff(CDerived1* other);
}

// Derived Class 2
class CDerived1: public CBase
{
void DoStuff(CDerived1* other);
}


What I want to do is Create A new object of the Same Type that is being
passed into my function
then call the apropriate function
my code currently looks like this:

void OtherFunction(CBase* MyDerived)
{
CBase* myNewBase = (CBase*)
MyDerived->GetRuntimeClass()->CreateObject();
myNewBase->DoStuff(MyDerived);
}

but this always calls CBase::DoStuff(CBase* other);
and I want it to call CDerived1::DoStuff(CDerived1* other);
or one of the other derived functions
the only way I can think of doing this is to use a lot of

if (myNewBase->IsKindOf(RUNTIME_CLASS(CDerived1)))
//cast then call
if (myNewBase->IsKindOf(RUNTIME_CLASS(CDerived2)))
//cast then call
if (myNewBase->IsKindOf(RUNTIME_CLASS(CDerived3)))
//cast then call


is there a better way to call the Derived Classes Member function?


thanks,

how



.



Relevant Pages

  • Re: derived class functions, with dif arg lists
    ... Declare the function in the base class to be virtual. ... > class CDerived1: public CBase ... > void DoStuff; ...
    (microsoft.public.vc.language)
  • Re: derived class functions, with dif arg lists
    ... void DoStuff; ... class CDerived1: public CBase ... > Declare the function in the base class to be virtual. ... >> class CDerived1: public CBase ...
    (microsoft.public.vc.language)
  • Re: inhibit compiler warning C4624 for a class hierarchy
    ... I'd really like to just pretend that the dynamic type is the base class. ... ** Carries a request or notification and any associated parameters. ... static void* operator new ... struct PNPEXPORT IConcurrentOperations::OpNotification abstract: public ...
    (microsoft.public.vc.language)
  • Re: Hooking automation object Events
    ... The next few lines of my post show the procedure SelectionChange: ... _PowerPCBDocEvents = dispinterface; ... void PowerPCBSink::OnFinalRelease ... // object before calling the base class. ...
    (comp.lang.pascal.delphi.misc)
  • RE: Protected keyword
    ... Only the Employee class internally can see the base class RaiseEvent method. ... public void HoldBreath{ ... a child that inherits from it so as to be able to call the protected method ...
    (microsoft.public.dotnet.languages.csharp)