As you wrote the code, it will not compile due to access control violations. Since b_ptr is of type a * and a::foo is private, the compiler will not allow this.
But make a::foo public, and that will call b::foo correctly.
There is also a problem that you did not define a::foo so that your program does not bind. You need to either define it or make it pure virtual (i.e. virtual void foo(void) = 0; ).
R Samuel Klatchko
source share