Hello

I just began to learn D. I have some experience with Visual Basic and (very little) C/C++. Last years I have been working with PHP.

So, I try to make up a class representation of a 52 cards deck. This way :

// sabot.d
// version 0.0.1
import std.stdio ;

void main(){
        auto deck = new sabot ;
}

class sabot{
        carte[] sabotarray ;

        this(){
                int i ;
                for (i=1 ; i<=52 ; i++){
                        carte tempcarte ;
                        tempcarte.id = i ;
                        sabotarray[] ~= tempcarte  ; // line 17
                }
                writeln(this.sabotarray[1]) ;
        }

        struct carte {
                int id ;
                string valeur_face ;
                int valeur_reelle ;
                int couleur ;
        }
}

But I get this error :
sabot.d(17): Error: cannot append type carte to type carte

I dont understand. Both sabaotarray[] and tempcarte are declared as carte type error message confirms). Why aren't they compatible ?

I tryed different things, but didn't get it work.

I can solve the problem by declaring a static array. But I would like to understand why this dont work.

Thank you


Reply via email to