简体   繁体   English

没有匹配的调用函数:const指向指针的指针

[英]No matching function for call : const pointer to pointer

I have the following function declaration 我有以下函数声明

int vectorQuantization(const Color **input, Color **output,
                       const int rows, const int cols, const int numColors);

and when I try to call it from my main function I get the error "No matching function for call to 'VectorQuantization' ". 当我尝试从主函数调用它时,出现错误“没有匹配函数来调用'VectorQuantization'”。

Color *input2quantize;
Color *outputQuantized;
...
...
vectorQuantization(&input2quantize, &outputQuantized, rows, cols, 10);

What I was trying to do is to make the input of the function constant so that it cannot be modified inside the function and I thought that declaring it as constant would make it. 我试图做的是使函数的输入成为常量,这样就不能在函数内部对其进行修改,而且我认为将其声明为常量将使它成为常量。 What am I missing here? 我在这里想念什么? I was thinking about using references instead pointer to pointer, but I got confused. 我当时在考虑使用引用而不是指针指针,但是我很困惑。 So two questions: 有两个问题:

  1. How can I fix this error? 如何解决此错误?
  2. Is it better to use references instead of const pointer to pointer? 使用引用而不是const指针会更好吗?

Say this: 说这个:

typedef Color * ColorPtr;

ColorPtr input2quantize;

int vectorQuantization(ColorPtr const * input);

vectorQuantization(&input2quantize);

If you like, you can spell the function argument type out as Color * const * input , too. 如果愿意,您也可以将函数参数类型拼写为Color * const * input

Note that this protects you from having the function change the pointer , not the pointee , which cannot be protected, since you have a mutable pointer. 请注意,这可以防止函数更改指针 ,而不能更改pointee ,因为有可变的指针,所以不能保护pointee。 If you wanted, you'd need a separate type: 如果需要,您需要一个单独的类型:

typedef Color const * SafeColorPtr;

SafeColorPtr safeinput = input2quantize;

int foo(SafeColorPtr const * pInput);

foo(&safeinput);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM