error: expected initializer before ‘.’ token void c.change();
时间: 2023-06-10 08:07:31 浏览: 121
这个错误通常是因为在函数体外部定义函数时,忘记了在函数名前面加上类名。在这种情况下,编译器会认为该函数是一个独立的函数,而不是类的成员函数。
请检查你的代码,确保在定义 `change()` 函数时,前面加上了类名。例如:
```
class MyClass {
public:
void change(); // 声明成员函数
};
void MyClass::change() { // 定义成员函数
// 函数体
}
```
如果你已经按照上面的方式定义了 `change()` 函数,但仍然出现了这个错误,请检查你的代码是否存在其他语法错误。
相关问题
error: expected initializer before ‘fopen’
这个错误通常表示你的代码中缺少了`#include <stdio.h>`头文件。请确保在使用`fopen`函数之前,已经包含了正确的头文件。
你可以在代码开头添加以下行来包含`<stdio.h>`头文件:
```cpp
#include <stdio.h>
```
这样,编译器就能正确识别并解析`fopen`函数。如果问题仍然存在,请检查代码的其他部分,确保没有其他语法错误或缺少其他必要的头文件。
error: expected initializer before ‘template’
这个错误通常是因为在定义模板时缺少了关键字 "class" 或 "typename"。请检查你的代码中是否有这个问题,特别是在定义类模板、函数模板或嵌套模板时。例如,下面的代码会出现这个错误:
```
template <int n> // 缺少 class 或 typename 关键字
struct my_array {
int data[n];
};
```
应该将其修改为:
```
template <class T, int n> // 添加 class 或 typename 关键字
struct my_array {
T data[n];
};
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)