g ++错误:'malloc'未在此范围内声明 [英] g++ error: ‘malloc’ was not declared in this scope
问题描述
我在Fedora下使用g ++来编译一个openGL项目,它具有以下行:
textureImage =(GLubyte * *)malloc的(的sizeof(GLubyte *)* RESOURCE_LENGTH);
编译时,g ++错误表示:
错误:'malloc'未在此范围内声明
添加 #include< cstdlib>
并不能解决这个错误。 我的g ++版本是: g ++(GCC)4.4.5 20101112(Red Hat 4.4.5-2)
<你应该在C ++代码中使用 new
而不是 malloc
,所以它变成新的GLubyte *改为[RESOURCE_LENGTH]
。当 #include
时,它会将 malloc
加载到命名空间 std
,所以引用 std :: malloc
(或者 #include
代替) 。
I'm using g++ under Fedora to compile an openGL project, which has the line:
textureImage = (GLubyte**)malloc(sizeof(GLubyte*)*RESOURCE_LENGTH);
When compiling, g++ error says:
error: ‘malloc’ was not declared in this scope
Adding #include <cstdlib>
doesn't fix the error.
My g++ version is: g++ (GCC) 4.4.5 20101112 (Red Hat 4.4.5-2)
You should use new
in C++ code rather than malloc
so it becomes new GLubyte*[RESOURCE_LENGTH]
instead. When you #include <cstdlib>
it will load malloc
into namespace std
, so refer to std::malloc
(or #include <stdlib.h>
instead).
这篇关于g ++错误:'malloc'未在此范围内声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!