Hello,
Did you actually try it? I know that that can make the difference
between runtime error and no runtime error. I thought it was kind of
odd too, but it is usually bad practice to pass an object by value
anyway. If you're worried about the object changing, you might be able
to write it as "const stat@ other".
I really think that is the problem.
This code gives me a runtime error:
"
class stat
{
int percent;
int opCmp(stat other)
{
return percent-other.percent;
}
}
stat[] stats;
void main()
{
stats.sort_descending();
}
"

And this code doesn't:
"
class stat
{
int percent;
int opCmp(stat@ other)
{
return percent-other.percent;
}
}
stat[] stats;
void main()
{
stats.sort_descending();
}
"
Best,
Aaron

On 2/18/16, john <[email protected]> wrote:
> Seems to be a nogo.
> I'd be surprised if that was the issue; handles are close enough to objects
>
> for it to not matter as function parameters in my experience.
>
> --------------------------------------------------
> From: "Aaron Baker" <[email protected]>
> Sent: Wednesday, February 17, 2016 19:51
> To: "Gamers Discussion list" <[email protected]>
> Subject: Re: [Audyssey] bgt operator overloading question
>
> Hey John,
> Try switching your parameter from "stat other" to "stat@ other".
> I think opCmp wants a handle (by reference), not a by value object.
> Best,
> Aaron
>
> On 2/17/16, john <[email protected]> wrote:
>> Hi all,
>> I'm attempting to overload comparison operators in order to sort an array
>>
>> of
>> objects, with the following function:
>> //begin code
>> int opCmp (stat other)
>> {
>> return percent-other.percent;
>> }
>> //end code
>> However, the program gives me the following error as soon as comparison
>> takes place:
>> A runtime error occurred. File:function: void main()Description: Type
>> 'stat'
>> does not have a matching opCmp method
>>
>>
>>
>> Can anybody shed some light on this one?
>>
>>
>>
>> Thanks,
>>
>> John
>>
>>
>>
>> P.S:
>>
>> Yes, the comparison function is within the stat class, and comparison is
>> being done by array.sort_descending.
>>
>> I have tried several case changes to the function name, and have stuck
>> with
>> the above because it matches both the manual and compiler error.
>> ---
>> Gamers mailing list __ [email protected]
>> If you want to leave the list, send E-mail to
>> [email protected].
>> You can make changes or update your subscription via the web, at
>> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
>> All messages are archived and can be searched and read at
>> http://www.mail-archive.com/[email protected].
>> If you have any questions or concerns regarding the management of the
>> list,
>> please send E-mail to [email protected].
>>
>
> ---
> Gamers mailing list __ [email protected]
> If you want to leave the list, send E-mail to
> [email protected].
> You can make changes or update your subscription via the web, at
> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
> All messages are archived and can be searched and read at
> http://www.mail-archive.com/[email protected].
> If you have any questions or concerns regarding the management of the list,
> please send E-mail to [email protected].
>
>
> ---
> Gamers mailing list __ [email protected]
> If you want to leave the list, send E-mail to
> [email protected].
> You can make changes or update your subscription via the web, at
> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
> All messages are archived and can be searched and read at
> http://www.mail-archive.com/[email protected].
> If you have any questions or concerns regarding the management of the list,
> please send E-mail to [email protected].
>

---
Gamers mailing list __ [email protected]
If you want to leave the list, send E-mail to [email protected].
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/[email protected].
If you have any questions or concerns regarding the management of the list,
please send E-mail to [email protected].

Reply via email to