我是新來的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