Re: virtualand nonvirtual templateness"
On Apr 11, 7:18 am, sasha <aborovin...@gmail.com> wrote:
I am bit confused as to whether the following is allowed; why and why
not:
1)
template<typename T>
class Foo{
...
virtual TsomeOp();
};
2)
template<typename T>
class Foo{
...
template<typename K>
virtual T someOp(K k);
};
3)
class Foo{
...
template<typename K>
virtual T someOp(K k);
};
What are the rules governing virtual member of a template class,
virtual template member of a template class and template member of non-
template class?
{ edits: quoted sig and banner removed please don't quote extraneous material -mod }
member functions of a c++ class or a class template can be virtual,
but
member function templates of c++ class or a class template can not be
virtual as they do not represent one function, they represent a family
of functions and can have multiple instantiations.
so
template <typename T>
class Foo
{
virtual void a();
virtual void b() = 0;
//a and b are legal declarations and can be virtual as they allways
//resolve to 1 function per the instance of the class type generated
//from the class template
template <typename T2>
virtual void c(){}
// where as c is an illegal definition as c is templated on a
template
// parameter T2 and is member function template, current compilers
can not necessary work out how many
// instances of c are gonna be instantiated across all different
translations
// units have been translated across the whole program, supporting
member function
// templates being virtual would require a whole new kind of
mechanism in c++ compilers and Linkers
};
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]