I'd like to know if compilers can optimize the following code. I'm interested in MSVC++ and g++.
Code:class Base
{
virtual void doSomething() = 0;
};
class Derived : public Base
{
void doSomething() { whatever; }
};
int main()
{
Derived* d = new Derived();
d->doSomething(); // Will this be called through the vtable?
// What if the object is on the stack?
}