我遇到了这个问题:
无效从'void*'转换为'uint8_t*'
这样做时:
int numBytes;
uint8_t *buffer;
buffer=malloc(numBytes); //error here, why?
Run Code Online (Sandbox Code Playgroud)
或者我必须这样说吗?
buffer=malloc(numBytes);
Run Code Online (Sandbox Code Playgroud)
请解释一下.
Oli*_*rth 17
你不能void *在C++中隐式地转换(在这方面与C不同).你可以这样做:
buffer = static_cast<uint8_t *>(malloc(numBytes));
Run Code Online (Sandbox Code Playgroud)
但实际上,你应该只使用new/ delete而不是malloc/ free!