[英]variable has incomplete type 'void' c++
我想出了一個學校作業的解決方案,但我無法編譯它。 我有五個錯誤,我相信它們都源於我沒有正確編寫我的 void 函數。 我仍然是編碼的新手,我無法弄清楚這一點。 幫助將不勝感激,謝謝!
當前代碼:
#include <iostream>
#include <string>
#include <algorithm>
void AddList(LinkedList<char>& List, std::string input)
{
for (int i = input.size()-1; i >=0; i--)
{
List.add(input[i]);
} // end for loop
} // end ListTester
bool ifSubString(LinkedList<char>& List, std::string input)
{
std::string fromTheList = List.toString();
return (fromTheList.find(subString) != std::string::npos);
}
void AppendList(LinkedList<char>& List, std::string input)
{
List.clear();
for (int i = input.size()-1; o >=0; i--)
{
List.add(input);
}
}
int main()
{
std::string userString, newstring, substring;
int choice;
char charInput;
LinkedList<char> listik;
std::cout << "Welcome to the linkedlist program\n" <<std::endl;
std::cout << "Please Enter the string before we start: ";
getline(std::cin, userString);
AddList(listik, userString);
std::cout << "The string \"" << userString << "\" has been added to the linked list.\n" << std::endl;
std::cout << "Menu: " << std::endl;
std::cout << "1. Find the length of your input." << std::endl;
std::cout << "2. Add a new string to the current string." << std::endl;
std::cout << "3. Find the index of the character." << std::endl;
std::cout << "4. Find matches in the string." << std::endl;
std::cout << "5. Quit and sleep" << std::endl;
std::cin >> choice;
std::cin.ignore();
while(choice!=5)
{
switch(choice)
{
case 1:
std::cout << "The List " << listik.toString() << " contains " << listik.getCurrentSize() << " elements." << std::endl;
std::cout << std::endl;
break;
case 2:
std::cout << "Please type the string you'd like to append to the current list: ";
getline(std::cin, newstring);
Appendlist(listik, (userString+newstring));
std::cout << "The list is \"" << listik.toString() << "\"." << std::endl; //AppendList function contains add method
std::cout << std::endl;
break;
case 3:
std::cout << "Please type the character you'd like to have the index of: ";
std::cin >> charInput;
std::cout << "The index of \"" << charInput << "\" is " << listik.getFrequencyOf(charInput) << std::endl;
std::cout << std::endl;
break;
case 4:
std::cout << "Please type the string you'd like to find in the current list: ";
getline(std::cin, subString);
std::cout << "The string \"" << subString << "\" is";
if (ifSubString(listik, subString)==false) std::cout << " not";
std::cout << "found in \"" << listik.toString() << "\"." << std::endl;
std::cout << std::endl;
break;
case 5:
listik.clear();
exit(0);
break;
}
}
}
我認為你復制了一份作業並在途中引入了一堆錯別字。 您需要填寫作業中的空白並實現類模板LinkedList
。
這是您已刪除拼寫錯誤的作業,您需要實現LinkedList
成員函數:
#include <iostream>
#include <string>
#include <algorithm>
template<class T>
struct LinkedList {
void add(T element);
std::string toString() const;
void clear();
int getCurrentSize() const;
int getFrequencyOf(T element) const;
};
void AddList(LinkedList<char>& List, std::string input)
{
for (int i = input.size()-1; i >=0; i--)
{
List.add(input[i]);
} // end for loop
} // end ListTester
bool ifSubString(LinkedList<char>& List, std::string input)
{
std::string fromTheList = List.toString();
return (fromTheList.find(input) != std::string::npos);
}
void AppendList(LinkedList<char>& List, std::string input)
{
List.clear();
for (int i = input.size()-1; i >=0; i--)
{
List.add(input[i]);
}
}
int main()
{
std::string userString, newstring, subString;
int choice;
char charInput;
LinkedList<char> listik;
std::cout << "Welcome to the linkedlist program\n" <<std::endl;
std::cout << "Please Enter the string before we start: ";
getline(std::cin, userString);
AddList(listik, userString);
std::cout << "The string \"" << userString << "\" has been added to the linked list.\n" << std::endl;
std::cout << "Menu: " << std::endl;
std::cout << "1. Find the length of your input." << std::endl;
std::cout << "2. Add a new string to the current string." << std::endl;
std::cout << "3. Find the index of the character." << std::endl;
std::cout << "4. Find matches in the string." << std::endl;
std::cout << "5. Quit and sleep" << std::endl;
std::cin >> choice;
std::cin.ignore();
while(choice!=5)
{
switch(choice)
{
case 1:
std::cout << "The List " << listik.toString() << " contains " << listik.getCurrentSize() << " elements." << std::endl;
std::cout << std::endl;
break;
case 2:
std::cout << "Please type the string you'd like to append to the current list: ";
getline(std::cin, newstring);
AppendList(listik, (userString+newstring));
std::cout << "The list is \"" << listik.toString() << "\"." << std::endl; //AppendList function contains add method
std::cout << std::endl;
break;
case 3:
std::cout << "Please type the character you'd like to have the index of: ";
std::cin >> charInput;
std::cout << "The index of \"" << charInput << "\" is " << listik.getFrequencyOf(charInput) << std::endl;
std::cout << std::endl;
break;
case 4:
std::cout << "Please type the string you'd like to find in the current list: ";
getline(std::cin, subString);
std::cout << "The string \"" << subString << "\" is";
if (ifSubString(listik, subString)==false) std::cout << " not";
std::cout << "found in \"" << listik.toString() << "\"." << std::endl;
std::cout << std::endl;
break;
case 5:
listik.clear();
exit(0);
break;
}
}
}
閱讀編譯器錯誤消息,它們會告訴您出了什么問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.