长度的左侧必须具有类/结构/nnion
left of .length must have class/struct/nnion
我是C 的新手,并且整体编程,并且我正在做一个分配,其中我创建了一个类,其中包含forname,姓氏和年龄的变量。这无济于事,但是当我将类向量传递到线性搜索功能时,我的问题就会出现,在该功能中,我会在其中获得"左侧的左侧/结构/结构/联合"的错误。我不知道为什么,在谷歌搜索大约一个小时后,我决定询问。
int linsok(Person p[], int n, int a)
{
cout << "Please enter the age of the person you want to find: ";
cin >> a;
for (n = 0; n < p->Person::Person.end(); n++)
{
if ( a = p->Person::Person.setAge)
{
cout << "The person you are looking for has the position " << n
<< " in the list." << endl;
}
else
return -1;
}}
要澄清,我的任务是创建一个线性搜索,该搜索通过向量进行搜索,以找到与搜索标准相匹配的人的年龄:a,如果没有找到该年龄的人,则返回-1。p>
请注意,p
不是std::vector
,它只是一个普通的旧数组。n
参数应表示其大小,因此:
for (int i = 0; i < n; ++i) {
// Code...
Person p[]
是一个数组。与std::vector<Person>
不同,它不能提供通过属性确定其长度的方法。这就是为什么n
传递给您的功能的原因,大概是为了指定数组中的元素数量。循环应该看起来像这样:
for (int i = 0; i < n ; i++)
您指的是人的年龄如下:
p[i].age // or getAge(), I don't see you Person's class
注意:范围分辨率::
语法更为高级。需要指定要调用哪种函数或在特定名称空间内使用哪种类型。在大多数情况下,您可以暂时忽略它。
相关文章:
- 如何循环打印顶点结构
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 预处理器:插入结构名称中的前一个行号
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 孤立代码块在结构中引发异常
- 有什么方法可以遍历结构吗
- 如何在 C# 中映射双 C 结构指针?
- 如何在C++中使用结构生成映射
- 无法将结构注册为增强几何体3D点
- 多成员Constexpr结构初始化
- C++将文本文件中的数据读取到结构数组中
- 如何重构类层次结构以避免菱形问题
- 如何在C++中序列化结构数据
- std::vector的包装器,使数组的结构看起来像结构的数组
- 没有为自己的结构调用列表推回方法
- 奇怪的结构&GCC&clang(void*返回类型)
- 在 c++ 中拥有一组结构的正确方法是什么?
- vscode g++链路故障:体系结构x86_64的未定义符号
- 长度的左侧必须具有类/结构/nnion