www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - variadic func to call another variadic func

reply Daniel919 <Daniel919 web.de> writes:
Hi, I tried to create a simple solution for constructor inheritance
(http://www.digitalmars.com/pnews/
read.php?server=news.digitalmars.com&group=digitalmars.D.announce&artnum=4426)

The example code illustrates the problem, called in the topic.

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

class Base {
     this() {
         m_val = -1;
     }

     this(int val) {
         m_val = val;
     }

     int m_val;
}

class Derived : Base {
     this(...) {
         super(_arguments); // <= the problem

         // ... do some special Derived constructor stuff
     }
}

void main() {
     Derived obj1 = new Derived();
     writefln("obj1.m_val: " ~ format(obj1.m_val));
     Derived obj2 = new Derived(12345);
     writefln("obj2.m_val: " ~ format(obj2.m_val));
}
--------------------------------------------------------------

The constructor of Derived has to call the constructor of Base with
the same parameters itself got called.

What would be the best way to do this ?

[Sorry for not posting this in digitalmars.D, but that forum isn't
working for me]

Thanks for your replies in advance,
Daniel
Aug 24 2006
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Daniel919 wrote:
 Hi, I tried to create a simple solution for constructor inheritance
 (http://www.digitalmars.com/pnews/
 read.php?server=news.digitalmars.com&group=digitalmars.D.announce&artnum=4426)
 
 The example code illustrates the problem, called in the topic.
 
 --------------------------------------------------------------
 import std.string;
 import std.stdio;
 
 class Base {
      this() {
          m_val = -1;
      }
 
      this(int val) {
          m_val = val;
      }
 
      int m_val;
 }
 
 class Derived : Base {
      this(...) {
          super(_arguments); // <= the problem
 
          // ... do some special Derived constructor stuff
      }
 }
 
 void main() {
      Derived obj1 = new Derived();
      writefln("obj1.m_val: " ~ format(obj1.m_val));
      Derived obj2 = new Derived(12345);
      writefln("obj2.m_val: " ~ format(obj2.m_val));
 }
 --------------------------------------------------------------
 
 The constructor of Derived has to call the constructor of Base with
 the same parameters itself got called.
 
 What would be the best way to do this ?
Currently the only way for variadic functions to pass their arguments forward is by making one's variadic functions dummy wrappers for workhorse functions taking the implicit variables as parameters... or in other words: There have been numerous proposals in the past for providing a cleaner way of doing this, including my own idea of making '...' at the call site an operator for building variadic parameter lists. -- Chris Nicholson-Sauls
Aug 24 2006