Question about: & operator.
#1

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..
Reply
#2

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; }
Reply
#3

I used C++ for a while and I almost forgot PAWN language...
Anyway, thanks
Reply
#4

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.
Reply
#5

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)