Does C++ virtual function call on derived object go through vtable?
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(); } Yes, it will use the vtable (only non-virtual methods bypass the vtable). To call B::foo() on b directly, call b->B::foo() . Most compilers will be smart