我是新来的C++和编程的整体,我正在做一个赋值,我创建了一个类Person,它包含forname,surname和age的变量。这工作没有问题,但我的问题出现时,我将类向量传递给我的线性搜索功能,我得到的错误“.end必须有类/结构/联合”。我不知道为什么,在Google搜索了大约一个小时后,我决定改为询问。.length的左边必须有class/struct/nnion
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;
}}
为了澄清,我的任务是创建一个通过矢量搜索线性搜索,找到一个符合搜索条件的人的年龄:一,并返回-1,如果没有人与年龄找到。
错误消息是因为Person :: Person不是结构类型实例的名称。你的代码中还有其他一些问题,你没有问过。在某种程度上,显而易见,你依靠猜测,而不是对C++的任何理解。特别是'Person p []'不是在C++中传递向量的方法。在尝试编写代码之前,尝试在课堂上聆听并阅读任何笔记或参考资料。 – Peter