+ 1
Why doesn't this compile?
Class A { template<class T> virtual void describe(T) {std::cout<<sizeof(T)<<std::endl;} }
1 Réponse
+ 3
First, class is written small and needs a semicolon at the end.
Second, template functions cannot be virtual, since the vtable would be of infinite size.
You can write your template on top of the class though, then for each type a new class is created, which has only one type for the vtable.
template<class T>
class A
{
//template<class T>
virtual void describe(T) {std::cout<<sizeof(T)<<std::endl;}
};