Question about: & operator. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question about: & operator. (
/showthread.php?tid=495889)
Question about: & operator. -
XStormiest - 19.02.2014
Ok, i have a single question if you can answer to me ...
In C++, there is an ampersand ( & ) that change the value of a variable when it returns it.
My question, is .. how can i use that operator :
Just look:
C++
Код:
int return_ovalue ( int& x) { x = x; return x; } // it return the value and also change it... :)
In PAWN: what i've tried:
Код:
stock SetVal(new& x) { x = x ;return x; } / the same thing as in c++
But whenever i compile i get errors..
Re: Question about: & operator. -
Lordzy - 19.02.2014
Quote:
Originally Posted by XStormiest
Ok, i have a single question if you can answer to me ...
In C++, there is an ampersand ( & ) that change the value of a variable when it returns it.
My question, is .. how can i use that operator :
Just look:
C++
Код:
int return_ovalue ( int& x) { x = x; return x; } // it return the value and also change it... :)
In PAWN: what i've tried:
Код:
stock SetVal(new& x) { x = x ;return x; } / the same thing as in c++
But whenever i compile i get errors..
|
PAWN is kinda different, you don't need to declare a variable inside the parameter options. It could be:
pawn Код:
stock SetVal(&x) { x= x; return x; }
Re: Question about: & operator. -
XStormiest - 19.02.2014
I used C++ for a while and I almost forgot PAWN language...
Anyway, thanks
Re: Question about: & operator. -
RajatPawar - 19.02.2014
EDIT: Didn't refresh the page. Ignore it, thanks!
Read about it here!
It's called referencing.
With that - you can pass an argument using the call - by - reference method to actually CHANGE the values of the variables you pass rather than just using call-by-value where you locally change it. ****** it!
I assume you should remove 'new' as you don't need that - only in C++ do you need to specify the data-type.
In PAWN -
pawn Код:
stock hello( &Float: hello ) {}
stock hello( &hello ) {}
stock hello( &bool: hello ) {}
....
are valid.
Re: Question about: & operator. -
XStormiest - 19.02.2014
Yeah, i got it now , Thanks again guys

As i said , i scripted for a long time in C++ as i'm now learning for school ( Some kind of Programming school ) , and yeah.... so thanks

and as i was used very much i forgot that PAWN doesn't have that much things as c++ or it have totally different..