In the following code, it calls a virtual function foo via a pointer to a derived object. Will this call go through the vtable or will it call B::foo
directly?
If it goes via a vtable, what would be a C++ idiomatic way of making it call B::foo
directly? I know that in this case I am always pointing to a B
.
Class A
{
public:
virtual void foo() {}
};
class B : public A
{
public:
virtual void foo() {}
};
int main()
{
B* b = new B();
b->foo();
}