[英]double pointer and const in c++
I used a function called 'calcHist' in opencv. 我在opencv中使用了一个名为“ calcHist”的函数。 And its declaration is:
它的声明是:
void calcHist(const Mat* arrays, int narrays, const int* channels, InputArray mask, OutputArray hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false )
I wrote a code snippets: 我写了一段代码片段:
Mat img = imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat* arrays = &img;
int narrays = 1;
int channels[] = { 0 };
InputArray mask = noArray();
Mat hist;
int dims = 1;
int histSize[] = { 256 };
float hranges[] = { 0.0, 255.0 };
float *ranges[] = { hranges };
calcHist(arrays, narrays, channels, mask, hist, dims, histSize, ranges);
and then got an error:IntelliSense: no instance of overloaded function "calcHist" matches the argument list 然后出现错误:IntelliSense:没有重载函数“ calcHist”的实例与参数列表匹配
But if I prefix 'const' to 'float *ranges[] = {ranges};' 但是,如果我将'const'前缀为'float * ranges [] = {ranges};' like
const float *ranges[] = { hranges };
像
const float *ranges[] = { hranges };
it's okay. 没关系。
So why this 'const' is necessary and the 'const' before histSize is not. 那么为什么要使用此“ const”,而不必选择histSize之前的“ const”。
T*
implicitly converts to const T*
. T*
隐式转换为const T*
。 Correspondingly, this means T**
implicitly converts to T*const*
. 相应地,这意味着
T**
隐式转换为T*const*
。 T*const*
is not const T**
, so this conversion doesn't work to let you make the function call. T*const*
不是const T**
,因此这种转换无法让您进行函数调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.