I am trying to import a C library into my C++ project but I'm stuck with this error
invalid conversion from 'void*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive] uint8_t const* raw = static_cast(getPointerToData(id, message->data, message->length)); ^ compilation terminated due to -Wfatal-errors.
This code compile well using C compiler but get this error using C++ one
bool XbusMessage_getDataItem(void* item, enum XsDataIdentifier id, struct XbusMessage const* message)
{
uint8_t const* raw = (getPointerToData(id, message->data, message->length));
Can you help me?
Thanks
You need to explicitly cast the return value from getPointerToData to const uint8_t*
. Implicit conversions between pointer types are not allowed in C++ but are in C.
Try:
uint8_t const* raw = static_cast<uint8_t const*>(getPointerToData(id, message->data, message->length));
Edit: You can also use a C-style cast if you want to keep the C code C and not C++.
uint8_t const* raw = (uint8_t const*)(getPointerToData(id, message->data, message->length));
This code posted by Jean-François Fabre works
uint8_t const* raw = (getPointerToData(id, static_cast<const uint8_t*>(message->data), message->length));
Thanks!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.