invalid conversion from ‘void*’ to ‘ifinfomsg*’ [-fpermissive]
时间: 2024-05-27 09:10:46 浏览: 10
This error occurs when you try to convert a void pointer to a pointer of a specific type, but the types are not compatible. In this case, you are trying to convert a void pointer to an ifinfomsg pointer, but they are not compatible.
To fix this error, you can cast the void pointer to the correct type before using it. For example:
void* void_ptr;
ifinfomsg* ifinfo_ptr = static_cast<ifinfomsg*>(void_ptr);
相关问题
[Error] invalid conversion from void* to char** [-fpermissive]
这个错误通常是由于将 `void*` 类型的指针直接赋值给 `char**` 类型的指针导致的。因为 `void*` 类型的指针可以指向任何类型的数据,而 `char**` 类型的指针只能指向 `char*` 类型的指针。
要解决这个问题,你需要先将 `void*` 类型的指针转换为 `char*` 类型的指针,然后再将其赋值给 `char**` 类型的指针。例如:
```c++
void* data = get_data();
char* char_data = static_cast<char*>(data);
char** char_ptr = &char_data;
```
这样就可以将 `void*` 类型的指针 `data` 转换为 `char**` 类型的指针 `char_ptr` 了。注意,这里使用了 `static_cast` 进行类型转换,如果你不确定类型转换是否安全,可以使用 `dynamic_cast` 进行安全的类型转换。
invalid conversion from void* to uint8_t
这个错误发生在将 `void*` 指针类型转换为 `uint8_t` 时。在 C++ 中,`void*` 是一种特殊的指针类型,可以指向任何类型的对象。但是,由于 `void*` 指针类型没有确定的大小,因此不能直接转换为其他指针类型或整数类型。
要解决这个错误,您应该首先确定为什么需要将 `void*` 指针转换为 `uint8_t` 类型。如果您只是想将指针作为一个字节序列进行处理,则可以使用 `reinterpret_cast` 将 `void*` 指针转换为 `uint8_t*` 指针,然后使用指针访问内存中的数据。
例如,假设您有一个 `void*` 指针 `ptr`,并且您想读取指针指向的内存中的第一个字节。您可以使用以下代码:
```
uint8_t* byte_ptr = reinterpret_cast<uint8_t*>(ptr);
uint8_t byte = *byte_ptr;
```
请注意,这种转换可能会导致未定义行为,因为您可能会尝试访问无效的内存地址。因此,在执行此类转换时,请确保您已正确地管理内存,并且您正在访问有效的内存地址。