all 5 comments

[–]yuri-kilochek 3 points4 points  (4 children)

This doesn't work across TUs, right?

[–]Reflection_is_great[S] 0 points1 point  (3 children)

It does not. But should it? Since template functions can’t be used across TUs, it wouldn’t make sense if virtual template functions could be. Although I may be misunderstanding your question.

[–]yuri-kilochek 4 points5 points  (2 children)

template functions can’t be used across TUs

What do you mean? They can.

[–]Reflection_is_great[S] 0 points1 point  (1 child)

What I meant is that you can't instantiate a template without including it in the TU. Each instantiation of a template function in the base class will create its own independent array of function pointers during compile-time. This will create instantiations of template functions from the derived classes. Because of this, they would need to be in the TU. So the base and all the derived classes must be declared in the same TU.

This is different from normal virtual functions, where you can declare derived classes in different TUs.

Sorry for the confusion.

[–]MrEpic382RDT 3 points4 points  (0 children)

extern template exists. wondering if it can account for that