Operator overloading

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


On Friday, 20 April 2012 at 14:10:31 UTC, Xan wrote:
> 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.

The full code is here: https://gist.github.com/2429005
(I put the code out of the class and I drop one error)


More information about the Digitalmars-d-learn mailing list