virtual function call from base of base

Posted by th3g0dr3d on Stack Overflow See other posts from Stack Overflow or by th3g0dr3d
Published on 2010-05-23T11:55:57Z Indexed on 2010/05/23 12:00 UTC
Read the original article Hit count: 666

Filed under:
|
|
|

hi,
let's say i have something like this (very simplified):

<pre><code>    

class base { void invoke() { this->foo(); } virtual void foo() = 0; };

class FirstDerived : public base { void foo() { // do stuff } };
class SecondDerived : public FirstDerived {
// other not related stuff }

int main() { SecondDerived *a = new SecondDerived(); a->invoke(); }

What i see in the debugger is that base::invoke() is called and tries to call this->foo(); (i expect FirstDerived::foo() to be called), the debugger takes me to some unfamiliar assembly code (probably because it jumped to unrelated areas) and after few lines i get segmentation fault.

am i doing something wrong here? :/

thanks in advance

© Stack Overflow or respective owner

Related posts about c++

Related posts about virtual