Re: call base class function or derived class function



Sorry, since I post a wrong section of code in the original question. so I
repost and ask for advice.

Here is the correct code. My question is simple and there is no
contradiction and I am just asking for why for the result as a best
description.

My question is, in main, function call goo through g.goo (called in function
goo in
class Foo) will call foo in class Goo, other than foo in class Foo, because
we are using an instance of Goo g and no matter execution in which class,
right?

[Code]
#include <iostream>

using namespace std;

class Foo {
public:
void goo()
{
foo(); // will call foo in class Goo
}
private:
virtual void foo() = 0;
};

void Foo::foo()
{
cout << "I am here. " << endl;
}

class Goo : public Foo {
public:
void foo()
{
Foo::foo();
}
};

int main()
{
Goo g;
g.goo();
return 0;
}
[/Code]


regards,
George
.



Relevant Pages

  • Re: Virtual function and multiple inheritance
    ... method in Derived which is not in Foo and Goo. ... virtual int myFunc() ... I'll make a guess that these two vtables are specific for Derived. ...
    (microsoft.public.vc.language)
  • Re: URGENT fast answer needed
    ... It will work similarly to grep except that it performs string replacement in addition to matching, and it does not support regular expressions or reading from standard input. ... our command will be called strep. ... foo a b c d foo e ... We could replace all occurrences of foo with goo as follows: ...
    (comp.lang.c)
  • Re: Virtual function and multiple inheritance
    ... containing two __vfptr is for the simple reason to maintain the ... It could be used in place of either a Foo or a Goo object, ... I'll make a guess that these two vtables are specific for Derived. ...
    (microsoft.public.vc.language)
  • Re: Virtual function and multiple inheritance
    ... __vfptr for Foo contains Derived overridden virtual methods for Foo, ... itself's virtual methods implementation, and __vfptr for Goo contains Derived ... Here pF is a pointer to an object with the same memory layout as a Foo ...
    (microsoft.public.vc.language)
  • Re: Virtual function and multiple inheritance
    ... virtual int func(); ... class Derived: Foo, Goo { ... Here pF is a pointer to an object with the same memory layout as a Foo and pG is a pointer to an object with the same memory layout as a Goo. ...
    (microsoft.public.vc.language)