[Error] request for member 'avg' in 's', which is of non-class type 'student [100]'
时间: 2024-01-17 11:04:08 浏览: 50
这个错误通常表示您正在尝试在一个数组上访问一个非静态成员,而数组不是一个类类型。请确保您正在使用正确的语法来访问该成员。
例如,如果您有一个名为“student”的类,并且您创建了一个名为“s”的类型为“student [100]”的数组,则可以使用以下语法访问单个学生的平均分数:
```
student s[100];
float avg = s[0].avg;
```
注意,这里我们使用“s[0]”而不是只是“s”,因为“s”是一个数组,而不是一个单独的对象。
相关问题
[Error] request for member 'pos' in 'k', which is of non-class type 'int'
This error occurs when you try to access the member variable 'pos' of an object 'k', but 'k' is not a class or struct type. This means that 'k' is probably defined as an integer or some other primitive data type, which does not have any member variables.
To fix this error, you need to make sure that 'k' is of a class or struct type that actually has a 'pos' member variable. Alternatively, you may need to adjust your code to use a different variable or approach that is appropriate for the data type of 'k'.
error: request for member 'Compare' in 'n', which is of non-class type 'int'|
这个错误通常是因为你尝试在一个非类类型的变量上调用一个成员函数。在你的代码中,变量 `n` 被声明为 `int` 类型,但是你尝试在它上面调用一个名为 `Compare` 的成员函数。这是不合法的,因为 `int` 类型没有 `Compare` 成员函数。
如果你想在一个类中使用 `Compare` 函数,你需要确保这个函数是该类的成员函数,并且你要在类的对象上调用它。如果你只是想在一个普通的函数中使用 `Compare` 函数,你需要将其定义为一个非成员函数,并传递任何必要的参数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)