replace double *tptr = malloc(n*sizeof(double));
登录 | 论坛导航 -> 华新鲜事 -> 社会百科 | 本帖共有 1 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:va (等级:1 - 微不足道,发帖:71) 发表:2003-07-01 22:38:10  楼主  关注此帖评分:
question regarding to C#include #include #include int main() { int n = 3; double *tptr = malloc(n*sizeof(double)); if (tptr != NULL) free(tptr); return 0; } got such error: error C2440: 'initializing' : cannot convert from 'void *' to 'double *' Conversion from 'void*' to pointer to non-'void' requires an explicit cast what's wrong with it? Thanks
replace double *tptr = malloc(n*sizeof(double));
with double *tptr = (double *) malloc(n*sizeof(double));

you need an explicit cast since malloc returns pointers of type void *. otherwise compiler will complain.
Put your OWN COOL signature here!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 社会百科 | 返回上一页 | 本主题共有 1 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码