C++ function resolution
I earn my living writing C++ code these days. Everyday I learn something new and interesting about this language. Many languages have a simple core, if you understand a few basic principles you can understand how most of the language works. C++ has a lot of esoteric features and no guiding principles that to borrow a term from human computer interaction allow the programmer to develop expectations. I think the reasons for this are historical. Reading Lippman’s Inside the C++ Object model and Stroustrup’s Design and Evolution of the C++ Programming language I am amazed by how much attention was paid to match C in performance
f() { a.f() // resolved at compile time (not polymorphic) p->f() // resolved at runtime }
The static resolution is a feature. The C++ compiler writers were trying to avoid the single instruction cost of vptr dereferencing. For a programmer this means that just marking a function as virtual does not mean that the most overriden version will be invoked. To ensure that every invocation must also be polymorphic. Also there is a principle at work here. You do not have to pay for what you do not use.