Kikito's 'middleclass' OOP Solution

In a language such as C++, in the simplest case of no compiler optimizations, if you had something like that Person class with a GetName function, that function’s compiled code would exist once in memory, and each Person object would have a pointer to it (the address of the function at runtime).

That said, any number of other things can happen with compiler optimizations: small functions will often get inlined with an optimization setting that favors speed over executable size, which could completely optimize the function out of existence. Places in your source code where you have person->GetName(), your executable might just have the code for the function body itself person.first + " " + person.last, with no actual function call.

1 Like