[C++] distinguish reference/value - 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: [C++] distinguish reference/value (
/showthread.php?tid=638480)
[C++] distinguish reference/value -
Baltazar - 01.08.2017
Hi, dudes. I try to write function-wrapper for retrieving float values in C++. Something like:
Код:
float GetFloat(AMX * amx, cell * params, int i);
I want it to work equally well when a floating-point number is passed by value or by reference:
Код:
native my_func(Float:f);
native his_func(&Float:f);
How do I know if a floating-point number was passed by value or by reference?
Re: [C++] distinguish reference/value -
Baltazar - 01.08.2017
I can always define two separate functions, like:
Код:
float GetFloatValueGiven(AMX * amx, cell * params, int i);
float GetFloatRefereceGiven(AMX * amx, cell * params, int i);
But I want my code to look nice. I would rather use one function for both cases. If only there is a way to distinguish whether float is passed by value or by reference.
Re: [C++] distinguish reference/value -
Baltazar - 02.08.2017
Ok, I will probably pass an additional parameter to determine the type manually as suggested:
Код:
float GetFloat(int index, bool is_reference = false);
SDK plugin is a very useful tool, unfortunately it is written mostly in C. I am trying to write a wrapper-class for it so it becomes more intuitive to use