chaining immutable methods vs functions

Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com> Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Thu Jan 16 17:49:22 PST 2014


Why do I get the error message:

Error: immutable method fbool.fbool.and is not callable using a 
mutable object

when chaining methods? It works fine using regular function calls?

struct fbool {
   ubyte data;
   pure immutable fbool and(immutable fbool b){return b.data < 
data ? b : this;}
   pure immutable fbool or(immutable fbool b){return b.data > data 
? b : this; }
   pure immutable fbool not(){ return fbool(data^255);}
}

immutable fbool not(immutable fbool a){ return fbool(a.data^255); 
}
immutable fbool and(immutable fbool a, immutable fbool b){ return 
a.data < b.data ? a : b;}
immutable fbool or(immutable fbool a, immutable fbool b){ return 
a.data > b.data ? a : b;}

or(and(not(a),b),and(not(a),b)); //this works
a.not().and(b).or( b.not().and(a) ); // this does not work


More information about the Digitalmars-d-learn mailing list