assigning a struct object to an array
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Fri Aug  7 02:24:14 PDT 2015
    
    
  
On 08/07/2015 02:05 AM, Reflexive wrote:
 > class sabot{
 >      carte[] sabotarray ;
 >
 >      this(){
 >          int i ;
 >          for (i=1 ; i<=52 ; i++){
 >              carte tempcarte ;
 >              tempcarte.id = i ;
 >              sabotarray[] ~= tempcarte  ; // line 17
dmd 2.068 gives a better message:
Error: slice expression this.sabotarray[] is not a modifiable lvalue
Just drop the []:
             sabotarray ~= tempcarte;
After all, the symbol 'sabotarray' represents the array and you want to 
append to it. On the other hand, sabotarray[] is a temporary slice, 
which happens to be an rvalue (read: not modifiable). You don't want to 
append to that temporary.
Ali
    
    
More information about the Digitalmars-d-learn
mailing list