5 ms·
"template<typename ABCType> foo(const ABCType& someObject)" will call the most optimized code path at compile time if the type is properly cast before the call.
by CoolGuySteve 7y ago
"template<typename ABCType> foo(const ABCType& someObject)" will call the most optimized code path at compile time if the type is properly cast before the call.
In this case, the inheritance is unnecessary as long as all the types implement the same function names. So the runtime type detection, whatever it is, only needs to be run once at the start of the callstack and then an entire chain of operations will be more optimized than if you had used interfaces and virtual functions throughout.
- MauranKilom 7y ago...and every single piece of code in your entire code base that touches these classes (and that's like 80% of the higher level code in this particular case) would have to be templated. So either everything has to be in headers, or you need 3 (well, 5 in reality, I abbreviated the example) explicit template instantiation declarations per function in the header and as many explicit template instantiation definitions in the source file. Either way lies madness.