Operator overloading -
Dabombber - 21.07.2009
I can't seem to get this to work correctly,
[code=pawn]#include <a_samp>
stock Something
perator--(Something
per)
return Something
_
per - 1);
stock Something
perator++(Something
per)
return Something
_
per + 1);
public OnFilterScriptInit()
{
new Something:a = Something:5, Something:b = Something:5;
a++;
b--;
printf("a = %i, b = %i", _:a, _:b);
return 1;
}[/code]
gives
but if I just have the decrement operator and not the increment operator it gives the expected value. Am I doing something wrong or is this a compiler problem?
Re: Operator overloading -
Correlli - 21.07.2009
I don't see any sense in here, ++, -- operators are already done in float.inc include.
Re: Operator overloading -
Dabombber - 21.07.2009
For floats, this is for a different type.
Re: Operator overloading -
Correlli - 21.07.2009
They can be used for integers, too.
Re: Operator overloading -
Dabombber - 21.07.2009
Everything in pawn is an integer
. The only reason floats work at all is because the operators are overloaded to use functions instead of the default operators. You can make your own type with your own operators which is what I'm trying to do but it doesn't seem to work properly.
Re: Operator overloading -
yezizhu - 21.07.2009
Код:
#include <a_samp>
stock Something:operator--(Something:oper)
{
new Something:value = oper;
Something:oper = Something:oper-Something:1;
return Something:(_:value);
}
stock Something:operator++(Something:oper){
new Something:value = oper;
Something:oper = Something:oper+Something:1;
return Something:(_:value);
}
public OnFilterScriptInit()
{
new Something:a = Something:5, Something:b = Something:5;
a++;
b--;
printf("a = %i, b = %i", _:a, _:b);
return 1;
}
Does it?
Edited: seems +(-)= need to overload, too.
Edited2:You don't need to overload if using operator as integer does
Quote:
Originally Posted by Don Correlli
I don't see any sense in here, ++, -- operators are already done in float.inc include.
|
You should know more about PAWN
Re: Operator overloading -
Correlli - 21.07.2009
Quote:
Originally Posted by yezizhu
You should know more about PAWN
|
I'm sure i know more than you probably, no need to tell me this.
Re: Operator overloading -
yezizhu - 21.07.2009
Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by yezizhu
You should know more about PAWN
|
I'm sure i know more than you probably, no need to tell me this.
|
Stop, if you wanna to, pm me please^^
Re: Operator overloading -
Correlli - 21.07.2009
Quote:
Originally Posted by yezizhu
Stop, if you wanna to, pm me please^^
|
You started it, but i don't want to argue with anyone, so quit it.
Re: Operator overloading -
Dabombber - 21.07.2009
I was wondering why floats worked and mine didn't so I tried
[code=pawn]#include <a_samp>
public OnFilterScriptInit()
{
new Float:a = 5, Float:b = 5;
a++;
b--;
printf("a = %.0f, b = %.0f", a, b);
return 1;
}[/code]
and got
so there's a pretty massive bug somewhere in the compiler.