clear initializing constructor

Wyverex wyverex.cypher at gmail.com
Mon Aug 4 13:43:33 PDT 2008


Not directly you can do something like

struct test
{
   bool A;
   int B;
   float C;
}

class foo
{
   private test t;

   this(test bar)
   {
    t = bar;
   }
}

void main()
{
   static test t = { A:true, C:4.5 };
   foo f = new foo( t);

}

But the static struct has to be filled by constants..

But it sounds like you might be better off using inheritance..
create a base Fruit class that you inherit and modify needed data..




Saaa wrote:
> Thanks for your reply.
> But I think  I wasn't clear in my question.
> As _Eigen can get quite large I think it is necessary to have something 
> like:
> 
> apple=new Fruit(color=RED,rotten=false);
> 
> otherwise thinks like this will happen:
> 
> apple=new Fruit(,,,RED,,false,,true etc.);
> 
> 
> 
> 
> 
>> class Fruit
>> {
>>
>>    protected struct _Eigen
>>    {
>>       byte color = GREEN;
>>       bool rotten = false;
>>    }
>>
>>     private _Eigen eigen;
>>
>>     this()
>>     {
>>     }
>>
>>     this(bool rotten, byte color)
>>     {
>>          eigen.rotten = rotten;
>>          eigen.color = color;
>>     }
>> }
>>
>> auto apple = new Fruit( false, RED );
>> auto normal = new Fruit(); 
> 
> 


More information about the Digitalmars-d-learn mailing list