digitalmars.D.learn - Is the template method non virtual?
- baleog <maccarka yahoo.com> Jul 16 2008
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> Jul 16 2008
- BCS <ao pathlink.com> Jul 16 2008
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?
thanks
p.s. dmd-2.0.16
Jul 16 2008
"baleog" <maccarka yahoo.com> wrote in message news:g5lmu2$2del$1 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.
Jul 16 2008
Reply to Jarrett,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.
It would not be possible to implement *with current linkers* I can think of some horrid hack's involving using relocations for vtbl offsets and generating object files by parsing link errors (or with a hacked linker) that would let it be done. OTOH it would break with .so/.dll usage and would generate some really funky build processes.
Jul 16 2008








BCS <ao pathlink.com>