Is there a preferred pattern for defining throwaway variables in C++ to pass to functions which take arguments by reference? One example of this is in using openCV's minmaxLoc function:
void minMaxLoc(const Mat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, const Mat& mask=Mat())
The function changes the value of minVal, maxVal, minLoc, maxLoc to correspond to the min/max intensity values and locations.
I could declare dummy variables for all of the parameters, but I really only need maxLoc. Is there a preferred C++ pattern such that I only declare maxLoc and don't clutter up my code with extra declarations of variables that I'm defining for the sake of calling minMaxLoc()?
In this specific case, you can pass nullptr for any out parameters whose results you do not need. See the OpenCV documentation (it's always good to read the documentation).
If the parameter is not optional, you need to declare local variables and pass their addresses. If you don't want this to clutter your code, write a helper function to encapsulate the clutter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With