Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;指针和函数交互导致的错误 我只使用C++大约3个星期,所以请耐心等待我,因为这个问题可能没有很好地形成(从数值分析开始可能不是个好主意)。我认为,这个问题与指针有关,可能很平常。我对指针有一个基本的掌握,但似乎有一些嵌套/交互正在进行。g++给了我一个编译器错误: In function ‘void test02()’: minpackTest01.cpp:95:50: error: invalid conversion from ‘void (*)(int, double*, double*, int*)’ to ‘void (*)(int*, double*, double*, int*)’ [-fpermissive] info = hybrd1_ ( f02, n, x, fvec, tol, wa, lwa ); ^ minpackTest01.cpp:95:50: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive] minpackTest01.cpp:95:50: error: cannot convert ‘double’ to ‘double*’ for argument ‘5’ to ‘void hybrd1_(void (*)(int*, double*, double*, int*), int*, double*, double*, double*, int*, double*, int*)’_C++_Pointers_Compiler Errors - Fatal编程技术网

C++;指针和函数交互导致的错误 我只使用C++大约3个星期,所以请耐心等待我,因为这个问题可能没有很好地形成(从数值分析开始可能不是个好主意)。我认为,这个问题与指针有关,可能很平常。我对指针有一个基本的掌握,但似乎有一些嵌套/交互正在进行。g++给了我一个编译器错误: In function ‘void test02()’: minpackTest01.cpp:95:50: error: invalid conversion from ‘void (*)(int, double*, double*, int*)’ to ‘void (*)(int*, double*, double*, int*)’ [-fpermissive] info = hybrd1_ ( f02, n, x, fvec, tol, wa, lwa ); ^ minpackTest01.cpp:95:50: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive] minpackTest01.cpp:95:50: error: cannot convert ‘double’ to ‘double*’ for argument ‘5’ to ‘void hybrd1_(void (*)(int*, double*, double*, int*), int*, double*, double*, double*, int*, double*, int*)’

C++;指针和函数交互导致的错误 我只使用C++大约3个星期,所以请耐心等待我,因为这个问题可能没有很好地形成(从数值分析开始可能不是个好主意)。我认为,这个问题与指针有关,可能很平常。我对指针有一个基本的掌握,但似乎有一些嵌套/交互正在进行。g++给了我一个编译器错误: In function ‘void test02()’: minpackTest01.cpp:95:50: error: invalid conversion from ‘void (*)(int, double*, double*, int*)’ to ‘void (*)(int*, double*, double*, int*)’ [-fpermissive] info = hybrd1_ ( f02, n, x, fvec, tol, wa, lwa ); ^ minpackTest01.cpp:95:50: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive] minpackTest01.cpp:95:50: error: cannot convert ‘double’ to ‘double*’ for argument ‘5’ to ‘void hybrd1_(void (*)(int*, double*, double*, int*), int*, double*, double*, double*, int*, double*, int*)’,c++,pointers,compiler-errors,C++,Pointers,Compiler Errors,标题中的函数显示为 /* find a zero of a system of N nonlinear functions in N variables by a modification of the Powell hybrid method (Jacobian calculated by a forward-difference approximation) */ void hybrd1_ ( void (*fcn)(int *n, double *x, double *fvec

标题中的函数显示为

/* find a zero of a system of N nonlinear functions in N variables by
   a modification of the Powell hybrid method (Jacobian calculated by
   a forward-difference approximation) */
void hybrd1_ ( void (*fcn)(int *n, double *x, double *fvec, int *iflag ), 
           int *n, double *x, double *fvec, double *tol, int *info,
           double *wa, int *lwa );
我的主代码在第95行出现问题“info=hybrd1_389;…”

#包括
#包括
#包括
#包含指数和伽马函数所需的//项
#在此处包含//奇怪的编译器调用
使用名称空间std;
使用arma;
//功能原型
int main();
void test02();
无效f02(整数n,双x[],双fvec[],整数*iflag);
//****************************************************************************80
int main()
//****************************************************************************80
//目的:
//MAIN是MINPACK_PRB的主程序。
//
//讨论:
//MINPACK_PRB测试MINPACK库。
//
{

无法比较签名:

void hybrd1_ ( void (*fcn)(int *n, double *x, double *fvec, int *iflag ), 
//                         ^^^^^^
//                         first arg is int*
您正在通过:

void f02( int n, double x[], double fvec[], int *iflag );
//        ^^^^^
//        first arg is int

其他参数类似地没有对齐-您正在传递一个
int
,其中
hybrd1
需要一个
int*
,等等。

比较签名:

void hybrd1_ ( void (*fcn)(int *n, double *x, double *fvec, int *iflag ), 
//                         ^^^^^^
//                         first arg is int*
您正在通过:

void f02( int n, double x[], double fvec[], int *iflag );
//        ^^^^^
//        first arg is int

其他参数类似地没有对齐-您正在传递一个
int
,其中
hybrd1
需要一个
int*
,等等。

这就是区别,解决方法是什么?如果我在f02()的原型声明和完整声明中都加上“int*n”)错误依然存在。@e5haffer修复方法是将正确的类型传递到函数中。(旁注,没有“原型声明”和“完整声明”-有“声明”和“定义”)。@e5haffer Make
fn
int*
作为其第一个参数。这就是区别,修复方法是什么?如果我将“int*n”作为参数在f02()的原型声明和完整声明中,错误仍然存在。@e5haffer修复方法是将正确的类型传递到函数中。(旁注,没有“原型声明”和“完整声明”-有“声明”和“定义”)。@e5haffer Make
fn
int*
作为其第一个参数。