January 2019
Intermediate to advanced
512 pages
14h 5m
English
We have gone so far down the rabbit hole of trying to erase every type in a C++ program, that we forgot why we started on this path in the first place. The original problem was that we did not want to write a new sort function for every type. C solved this problem by erasing the types and using void* pointers, but in doing so, it put all responsibility for the correctness of the code on the programmer—neither the compiler, nor the runtime system, can detect when the argument types do not match the function called.
Making every function virtual offers a very cumbersome solution to this problem. C++ has a much more elegant one—templates. A template function is, in a sense, the opposite of the erased type—on ...
Read now
Unlock full access