Template method overloading
Kirk McDonald
kirklin.mcdonald at gmail.com
Tue Jan 23 12:34:34 PST 2007
Dominic Letz wrote:
> Hello,
>
> I'm trying to overload a template method. But it seems not to produce the expected result, although everything is compiling fine.
>
> My sample is this: (Compiled with win32 dmd version 1.0). I expect:
> A is called with 1
> B is called with 2
> But I got this:
> A is called with 1
> A is called with 2
>
> the file:
> import std.stdio;
> class A
> {
> void someMethod(T)(T i)
> {
> writefln("A is called with %d", i);
> }
> }
> class B : A
> {
> void someMethod(T)(T i)
> {
> writefln("B is called with %d", i);
> }
> }
> int main()
> {
> A test = new A();
> test.someMethod(1);
> test = new B();
> test.someMethod(2);
> return 0;
> }
>
Template member functions are implicitly 'final.' This is a consequence
of how templates work. They cannot exist in the vtable.
--
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list