January 31st, 2014, 04:49 AM
Why is the CRTP used instead of virtual functions?
I was reading about the CRTP, and I can't for the life of me understand it's advantages over virtual functions.
Unless you're coding embedded systems, and can't afford the few extra bytes for the vptr, or coding something requiring high-performance, where every nanosecond counts, I just don't see why the CRTP is so attractive. It just adds more text and forces every user class that wants to use the CRTP'd hierarchy to become a template class.
I tried implementing my Functor hierarchy with the CRTP instead of virtual functions...All it did was clutter my files with angle brackets and made the whole thing look very ugly.
Please, enlighten this chick.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.