I'm quite new to c++ and I don't manage to make this works. Sorry but i have always worked with languages that didn't helped me to think in terms of memory pointers ans so maybe this is a fooly question.
I want to pass a float array as a default parameter. Like this:
void getHistogram(const Mat& src, MatND& hist, float range[]=NULL) {
if(range==NULL) {
double maxPixel=0;
minMaxLoc(src, 0, &maxPixel, 0, 0);
range = { 0, maxPixel +1 };
}
// now calculate histogram with the right range
// something something
}
I have tried with some different syntax but i'm always in front on some errors like
histogram.cpp:21: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
histogram.cpp:21: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘float*’ in assignment
EDIT (but with memory leak):
Ok, thatnks to this answer i have resolved in this way:
void imHist(const Mat& src, MatND& hist, float range[]=NULL) {
if(range==NULL) {
double maxPixel=0;
minMaxLoc(src, 0, &maxPixel, 0, 0);
range = new float[2];
range[0] = 0;
range[1] = maxPixel +1;
}
}
some pros or cons?
EDIT 2
see the accepted answer