C ++:malloc:error:从“void *”到“uint8_t *”的无效转换 [英] C++: malloc : error: invalid conversion from ‘void*’ to ‘uint8_t*’
问题描述
我遇到这个问题:
从void *到uint8_t *的无效转换
执行此操作时:
int numBytes;
uint8_t * buffer;
buffer = malloc(numBytes); //错误这里,为什么?
还是我必须这样吗?
buffer = malloc(numBytes);
请说明...
。
您不能从C ++中的 void *
(不像C在这方面)。您可以:
buffer = static_cast< uint8_t *>(malloc(numBytes));
但实际上你应该使用 I got this problem: invalid conversion from ‘void*’ to ‘uint8_t*’ When doing this: or must I have to put it like this? Please explain... Thanks in advance. You cannot implicitly cast from but really, you should just be using 这篇关于C ++:malloc:error:从“void *”到“uint8_t *”的无效转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! new
/ delete
而不是 malloc
/ p>
int numBytes;
uint8_t *buffer;
buffer=malloc(numBytes); //error here, why?
buffer=malloc(numBytes);
void *
in C++ (unlike C in this respect). You could do:buffer = static_cast<uint8_t *>(malloc(numBytes));
new
/delete
instead of malloc
/free
!