Virtual function question

From: BCC (bryan_at_akanta.com)
Date: 06/30/04


Date: Wed, 30 Jun 2004 17:34:08 GMT

Hi,

If I have a base class with a virtual function defined:
class CBase {
  virtual void Foo();
};

void CBase::Foo()
{
  // base class functionality
}

and a derived class which overrides the base class Foo():
class CDerived: public CBase {
  void Foo();
};

CDerived::Foo()
{
  // derived functionality
}

If I had a pointer to an object of type CDerived, how can I call the base
classes version of Foo() rather than the polymorphic version?
CDerived derived;
CDerived* p_derived = &derived;
p_derived->Foo(); // Want to somehow be able to call base class Foo()!

I think there is a simple way to do this, but I can't find it.

Thanks,
B



Relevant Pages

  • Re: The lack of default function parameter in C99 makes compatibility difficult.
    ... Assume that you have written a library using plain standard C99 and you want ... to extend the functionality of a function. ... void foo ... new functionality is added to foo ...
    (comp.lang.c)
  • Re: Casting up to inheriting class from base?
    ... void Update ... How can I have the base class know which instance class has inherited ... make Foo() virtual. ...
    (microsoft.public.dotnet.languages.csharp)
  • 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: Convenience constructors and non-final setters
    ... any subclass has no choice than use ... functionality, the base class might be better off as an interface. ... ColoredCartPoint and ColoredPolarPoint concrete subclasses that implement ...
    (comp.lang.java.programmer)