[C++] distinguish reference/value
#1

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)