main.cc:244:36: error: invalid conversion from ‘void*’ to ‘std::vector<Airline>*’ [-fpermissive] 244 | vector<Airline>* shared = shmat(shmid, nullptr, 0); | ~~~~~^~~~~~~~~~~~~~~~~~~ | | | void*
时间: 2023-10-19 15:07:31 浏览: 76
这个错误提示是因为在代码的第244行中,将一个`void*`类型的指针直接赋值给了`std::vector<Airline>*`类型的指针,这是一种无效的转换。
`shmat()`函数返回的是`void*`类型的指针,它表示共享内存区域的起始地址。然而,你试图将这个`void*`指针直接赋值给一个`std::vector<Airline>*`类型的指针变量 `shared`,这是不正确的。
要解决这个错误,你需要使用`static_cast`或者C风格的类型转换将`void*`指针转换为正确的类型。对于指针类型之间的转换,可以使用`static_cast`进行显式转换,如下所示:
```cpp
vector<Airline>* shared = static_cast<vector<Airline>*>(shmat(shmid, nullptr, 0));
```
或者使用C风格的强制类型转换:
```cpp
vector<Airline>* shared = (vector<Airline>*)shmat(shmid, nullptr, 0);
```
请注意,在进行指针类型转换时要格外小心,确保转换是安全和合理的,以避免潜在的运行时错误。
相关问题
main.cpp:44: error: invalid conversion from 'const QPaintDevice*' to 'QPaintDevice*' [-fpermissive] QPainter painter(&window);
这个错误提示说明您在使用 `QPainter` 类时传递了一个常量指针,而 `QPainter` 的构造函数需要一个非常量指针作为参数。
请检查您的代码中调用 `QPainter` 构造函数时传递的参数是否正确。如果传递的参数是一个常量指针,您可以尝试将其转换为非常量指针,例如:
```cpp
const QPaintDevice* device = ...;
QPainter painter(const_cast<QPaintDevice*>(device));
```
注意,这种方式可能会有一些潜在的安全问题,请谨慎使用。如果您不确定如何处理这个问题,请提供更多的上下文信息,以便我更好地帮助您解决问题。
修改error: invalid conversion from ‘char**’ to ‘int’
这个错误是因为你将一个指向指针的指针(char**)赋值给了一个整型(int)。你需要将其转换为正确的类型。
例如,如果你想将一个指向字符串的指针数组赋值给一个整型变量,你可以使用数组的第一个元素的地址,如下所示:
```
char* strArr[] = {"Hello", "World", "!"};
int num = (int)(strArr[0]);
```
这样,num就会包含字符串 "Hello" 的地址,而不是整个字符串数组的地址。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)