I would like to write a function in C++ that takes a matrix as an optional argument. If the user ends up passing the matrix when calling the function, it will be modified by the function, so I'm implementing a pass by reference.
According to the accepted answer for this previous question, this can be done by making the default value an empty Mat, such as:
void foo(..., cv::Mat &matrix = cv::Mat()) {
// code
return;
}
However, when I try to compile this in OpenCV 3.2, I get the «invalid initialization of non-const reference of type ‘cv::Mat&’ from an rvalue of type ‘cv::Mat’» error.
Has this feature changed since OpenCV 2.4, or could the issue be somewhere else?