Inheritance Question

From: BCC (bcc_at_akanta.com)
Date: 01/28/05


Date: Fri, 28 Jan 2005 18:35:26 GMT

If I have a base class like this:

class A {
public:
    void Foo() { Foo1(); }
    void Foo1() { Foo2(); }
    void Foo2() { int x = 0; }
};

And I derive from it and override Foo2():
class B: public A {
public:
    void Foo2() { int y = 1; }
}

Now if I call Foo() from an instance of my derived class:
B b;
b.Foo();

When it gets to Foo2() it calls the Foo2() from my base class and not my
derived class.

Is this normal behavior? So if I want to override one small function buried
in several other function calls I have to explicitly override all those
functions in my derived class?

Thanks,
Bryan



Relevant Pages

  • Re: Inheritance Question
    ... > Now if I call Foo() from an instance of my derived class: ... this pointer is to an A object. ... it wouldn't call Foo2 of a B object. ... So if I want to override one small function buried ...
    (comp.lang.cpp)
  • Re: Inheritance Question
    ... BCC wrote: ... So if I want to override one small function buried ... > in several other function calls I have to explicitly override all those ... Make foo2 in A a virtual. ...
    (comp.lang.cpp)
  • Re: What can I store in LPARAM
    ... I'm not saying you're wrong, but with my call back up to the base class, ... may choose to override it completely, or by adding code before or after ... comments below regarding leaf. ... This means that a subclass can't change the method body behind ...
    (microsoft.public.vc.mfc)
  • Re: How many bytes per Italian character?
    ... override the InitState() function so it needs to be pure virtual. ... derived classes call up to them anyway; ... both the base class and derived class. ...
    (microsoft.public.vc.mfc)
  • Re: Overriding "OnXXX" versus adding event handler
    ... to touch base functionality and not to deal with component ... Either for base class or for my class. ... For example, you can either write a new OnPaint override, or you can ... In other words, override when you can, add an event handler if you can't. ...
    (microsoft.public.dotnet.framework)