1

The following is the method signature in a class.

virtual void evaluate(const double *var, double *obj, double *constr) const = 0;

virtual void evaluate(unsigned int numPoints, const double **var, double **obj, double **constr) const {
    //do something
}

Here is the declaration of arguments

unsigned int size;
double **var = new double*[size];
double **obj = new double*[size];
double **constr = new double*[size];

Here is the method call.

evaluator.evaluate(size, var, obj, constr);

I get the following compiler error.

foo.cpp: In member function âvoid foo::evaluatePopulation(std::vector<Individual, std::allocator<Individual> >&, unsigned int, bool)â:
foo.cpp:347: error: no matching function for call to foo::evaluate(unsigned int&, double**&, double**&, double**&) constâ
foo.h:35: note: candidates are: virtual void foo::evaluate(const double*, double*, double*) const
foo.h:43: note:                 virtual void foo::evaluate(unsigned int, const double**, double**, double**) const <near match>

foo are class names. I am using double pointers (two asterisks). How do I resolve this error?

4

1 回答 1

3

在您的第二个签名中,第二个形参的类型var, 是const double**。实际参数 ,constrdouble**无法隐式转换为前一种类型的类型。

例子

#include <stdio.h>

void fn(const int** pp)
{
    printf("%p : %p : %d", pp, *pp, **pp);
}

int main()
{
    int n = 1;
    int *p = &n;
    fn(&p); // ERROR. see below
    return 0;
}

报告的错误是准确的:

main.c:17:8:传递'int **'给类型的参数'const int **'会丢弃嵌套指针类型中的限定符。

于 2013-09-05T16:12:08.707 回答