Friday 15 January 2010

c++ - Best way of calling a function with different arguments passed by reference when you only need one of these arguments -


This is a simple question:

If I want to call a method like this, for example :

  gets zero bot (float and exmin, float and yum, float and zmin, float and xmx, float and wamax, float and gmx)   

What is the correct way to call the method, if I need the information stored in XMX? I do not want to make the variable which I am not using.

Is there any way to do this? Let's say what would be the wrong way to do this:

  float xmax; Getbounds (nullptr, nullptr, nullptr, xmax, nullptr, nullptr);   

Now I am using dummy-trash variables, but there is probably another way.

Thanks in advance.

EDIT: Sorry, I forgot to tell that I can not edit the law, from the third party's library.

Do you modify the getBounds or not? If you can, and calculating each of the values ​​is expensive, then it may be possible to pass this indication, and if only relevant indicator then the pointer is non-empty Otherwise, you have to pass a new value for each and theoretically, if you pass more than one argument in the same variable, then you can get undefined behavior in the function (say that the function Starts with something on the lines of "code = xmin = ymin = 0.0" ).

Finally, unless the calculation of each value is not expensive, and the function leaves it if it receives a null pointer, then creating and passing additional variables have no effect on the display There is no possibility of it.



No comments:

Post a Comment