类型:转载 责任编辑:asp 日期:2007/03/01
(1)void function(double (* pf)(double * x),int n, double *point,
double * grad);
这个函数的声明中的double (* pf)(double * x)怎么解释?
(2)msdn上malloc的例子为什么会出错,运行提示:
error c2440: = : cannot convert from void * to char *
conversion from void* to pointer to non-void requires an explicit cast
#include <stdlib.h> /* for _max_path definition */
#include <stdio.h>
#include <malloc.h>
void main( void )
{
char *string;
/* allocate space for a path name */
string = malloc( _max_path );
if( string == null )
printf( "insufficient memory available\n" );
else
{
printf( "memory space allocated for path name\n" );
free( string );
printf( "memory freed\n" );
}
}
推荐阅读
(1):表示函数function第一个参数为一个"返回值为double,参数为double *"的函数指针。
1 函数指针!
2 string = malloc( _max_path );
(2):c++的编译器对类型检验非常严格,这可能是 msdn疏忽了,加上强制转换就 ok了。
string = (char *)malloc( _max_path );
1、double (* pf)(double * x) 函数指针,返回值为double,参数为double *
2、string = (char *)malloc( _max_path );
double (* pf)(double * x)函数指针
参数是double *类型
返回值也是
malloc()的返回值是void *
up
.