November 24, 2006
Hi,

this code is perfectly valid and working
with dmd 0.174:
------------------------------------------------
import std.stdio;

class Base
{
   this()
   {
      value = 0;
   }

   this(int a)
   {
      value = a;
   }

   int value;
}


class Derived (A...) : Base
{
   this(A a)
   {
      super(a);
   }
}

int main(char[][] args)
{
   Derived!(int) derived = new Derived!(int)(1);
   writefln(derived.value);
   return 0;
}
------------------------------------------------

But I would like to use implicit template
instantiation on constructor this as well.
So it would look like:

------------------------------------------------
...
class Derived : Base
{
   this(A...)(A a)
   {
      super(a);
   }
}
...
Derived derived = new Derived(1);
...
------------------------------------------------

Couldn't the constructor be implicitly templated, like
member function's, for example:
void print(A...)(A a) { } ?

Thanks for your replies in advance

Daniel
December 01, 2006
Hi, implicit template instantiation is working for
other class members as expected (first code example shown below).

So why not make it working for constructor "this", too ?
Is this feature just missing or is it technically impossible ?

In the former case I would be pleased to see this feature on the todo list, because it would solve the problem of constructor inheritance
(like I showed in my last post to this topic, which is quoted below).

Thanks in advance

------------------------------------------------
import std.stdio;

class Base
{
   this() {}

   void init()
   {
      value = 0;
   }

   void init(int a)
   {
      value = a;
   }

   int value;
}


class Derived : Base
{
   this() {}

   void superinit(A...)(A a)
   {
      init(a);
   }
}

int main(char[][] args)
{
   Derived derived;

   derived = new Derived();
   derived.superinit();
   writefln(derived.value);
   delete(derived);

   derived = new Derived();
   derived.superinit(1);
   writefln(derived.value);
   delete(derived);
   return 0;
}
------------------------------------------------




Daniel919 wrote:
> Hi,
> 
> this code is perfectly valid and working
> with dmd 0.174:
> ------------------------------------------------
> import std.stdio;
> 
> class Base
> {
>    this()
>    {
>       value = 0;
>    }
> 
>    this(int a)
>    {
>       value = a;
>    }
> 
>    int value;
> }
> 
> 
> class Derived (A...) : Base
> {
>    this(A a)
>    {
>       super(a);
>    }
> }
> 
> int main(char[][] args)
> {
>    Derived!(int) derived = new Derived!(int)(1);
>    writefln(derived.value);
>    return 0;
> }
> ------------------------------------------------
> 
> But I would like to use implicit template
> instantiation on constructor this as well.
> So it would look like:
> 
> ------------------------------------------------
> ...
> class Derived : Base
> {
>    this(A...)(A a)
>    {
>       super(a);
>    }
> }
> ...
> Derived derived = new Derived(1);
> ...
> ------------------------------------------------
> 
> Couldn't the constructor be implicitly templated, like
> member function's, for example:
> void print(A...)(A a) { } ?
> 
> Thanks for your replies in advance
> 
> Daniel