Operator overloading

Xan xancorreu at gmail.com
Fri Apr 20 12:29:42 PDT 2012


On Friday, 20 April 2012 at 18:47:14 UTC, Dmitry Olshansky wrote:
> On 20.04.2012 19:14, Xan wrote:
>> On Friday, 20 April 2012 at 14:18:37 UTC, Dmitry Olshansky 
>> wrote:
>>> On 20.04.2012 18:10, Xan wrote:
>>>> What fails if I want to define this:
>>>>
>>>> Algorisme!(T,V) opBinary(string op)(Algorisme!(T,U) alg) {
>>>
>>> Algorisme!(T,V) opBinary(string op, T)(Algorisme!(T,U) alg) {
>>>
>>> You need to name what T is and that is *sometype*. Anyway I 
>>> suggest
>>> getting a decent book (TDPL).
>>>
>>>> if (op=="*") {
>>>
>>> static if is conceptually and technically better here.
>>
>>
>> Thanks, Dmitry, for your suggestions, but it does not work too:
>>
>> $ gdmd-4.6 algorisme
>> algorisme.d:54: Error: 'alg' is not of arithmetic type, it is a
>> algorisme.Algorisme!(int,int).Algorisme
>> algorisme.d:54: Error: 'alg2' is not of arithmetic type, it is 
>> a
>> algorisme.Algorisme!(int,int).Algorisme
>>
>>
>> I update de gist: https://gist.github.com/2429005
>>
>> By the other hand, is there any way to put the definition of 
>> operator *
>> in the class (not out like I have now)?
>>
>
> it should be inside the class. Why would you put it outside and 
> hope it work? What 'this' can refer to in free function?

Yes, you're wright. So in.

But what fails?

I reveice these errors and I have no idea what fails!


>
> Please read spec at the very least.
> http://dlang.org/operatoroverloading.html

I read it. It served me as guide. But not I'm in trouble....
Can you help me fixing the bug!

Regards,
Xan.


>
>>
>> Thanks,
>> Xan.





More information about the Digitalmars-d-learn mailing list