Bloomberg LP Interview Question
Software Engineer / DevelopersYou can make a function virtual inside template class,
but you cannot make a template virtual function inside a class.
Another words:
template <class T> class A
{
virtual void f(); // possible, creates vtable pointer, class size = 4
};
class A
{
template <class T> virtual void f(); //impossible: compiler does not know how to make vtable (they will be different for each type)
};
You can make a function virtual inside template class,
but you cannot make a template virtual function inside a class.
Another words:
template <class T> class A
{
virtual void f(); // possible, creates vtable pointer, class size = 4
};
class A
{
template <class T> virtual void f(); //impossible: compiler does not know how to make vtable (they will be different for each type)
};
No. It gives compilation error!
- Anonymous August 10, 2010