Is the template method non virtual?

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Jul 16 14:18:49 PDT 2008


"baleog" <maccarka at yahoo.com> wrote in message 
news:g5lmu2$2del$1 at digitalmars.com...
> Here is the test code:
> --
> class A {
>  bool f1() { return false; }
>  bool f2(T)() { return false; }
> }
>
> class B : A {
>  bool f1() { return true; }
>  bool f2(T)() { return true; }
> }
>
> void main()
> {
>  A a = new B;
>  assert(a.f1()); // OK
>  assert(a.f2!(int)()); // assert error
> }
> --
> Is it a regular behaviour? And what should I do to implement a virtual 
> templated method?

Yes, all templated methods are implicitly final (non-virtual).

There is no way to have a virtual templated method.  It would not be 
possible to implement, since there can be any number of instantiations of 
the method. 




More information about the Digitalmars-d-learn mailing list