Original Post
🔒 Locked
virtual teplate
Advertisement
No.
Because virtuality is generally implemented in C++ with vtables. The concept of a template is that for each combination of template arguments used, a new, entirely separate function is created. Because of that, in order for it to work with a vtable, the compiler/linker would have to know all of the different instantiations that will possibly be used via the base, make appropriate vtable entries for each, and be sure that all translation units index it correctly -- not to mention that it pretty much completely gets rid of the possibility to use the function from other executables which would link to it if they were to use unexpected instantiations.
Instead of making the template virtual, just make non-template virtual functions for the stuff that you need to be virtual, then make a non-virtual template which calls the appropriate virtual functions.
Instead of making the template virtual, just make non-template virtual functions for the stuff that you need to be virtual, then make a non-virtual template which calls the appropriate virtual functions.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement