Operator overloading

Xan xancorreu at gmail.com
Fri Apr 20 07:10:29 PDT 2012


What fails if I want to define this:

	Algorisme!(T,V) opBinary(string op)(Algorisme!(T,U) alg) {
		if (op=="*") {
			//fer la funció composicio
			return new Algorisme!(T,V)("Composició de "~this.nom ~ " i " 
~ alg.nom, 1, function(T t) { return this.funcio(alg.funcio(t)); 
} );
		}
	}

}


within my
class Algorisme(U,V) {
	string nom;
	uint versio;
	alias V function (U) Funcio;
	Funcio funcio;
...
}

?


I want to combine Algorisme(U,V) and Algorisme(T,V) with 
operator. Is it possible?

The errors I get are:

  gdmd-4.6 algorisme
algorisme.d:32: Error: undefined identifier T, did you mean 
variable E?
algorisme.d:51: Error: 'alg' is not of arithmetic type, it is a 
algorisme.Algorisme!(int,int).Algorisme
algorisme.d:51: Error: 'alg2' is not of arithmetic type, it is a 
algorisme.Algorisme!(int,int).Algorisme



Thanks in advance,
Xan.



More information about the Digitalmars-d-learn mailing list