3 ms·
I haven't looked at the code, but if you have multiple leaves, even marking all of them as final won't help if the call is through a base class.
by gpderetta 3y ago
I haven't looked at the code, but if you have multiple leaves, even marking all of them as final won't help if the call is through a base class.
- jeffbee 3y agoYeah the practical cases for devirtualization are when you have a base class, a derived class that you actually use, and another derived class that you use in tests. For your release binary the tests aren't visible so that can all be devirtualized. In cases where you have Dog and Goose that both derive from Animal and then you have std::vector<Animal>, what is the compiler supposed to do?
- kccqzy 3y agoThe compiler simply knows that the actual dynamic type is Animal because it is not a pointer. You need Animal* to trigger all the fun virtual dispatch stuff.