我在大學的計算機科學課。我正在完成一項即將到期的任務,但我遇到了一個問題,我厭倦了等待老師回覆我的電子郵件。我們使用Visual Studio 2015學習使用C++進行編碼,並通過用戶定義的函數,數組和結構體獲得。我們沒有做任何有關課程或任何事情的任何事情,並且我發現的關於我所得到的錯誤的所有信息似乎涉及這些,因此對我沒有幫助。C++:數組作爲函數形式參數讓我錯誤
每當我跑我的程序,我得到以下錯誤:
「LNK2019解析的外部符號 「無效__cdecl takeOrder(INT,INT,結構menuItemType *常量)」(?takeOrder @@ YAXHHQAUmenuItemType @@@ Z)在函數引用_main
LNK1120 1周無法解析的外部」
被說成是在這兩個錯誤‘線1’。
Visual Studio網站上的文檔有點過於誇張,我不瞭解所有的信息,但我認爲它與我的變量聲明有關。這是唯一有意義的事情。
我對數組沒有很好的理解,但我認爲我正確地使用它們。我有兩倍,三倍,四倍檢查教科書,筆記和拼寫,我不知道我錯過了什麼。下面是完整的代碼(保存一些只是使它更長的東西)。
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cstring>
using namespace std;
struct menuItemType
{
string itemName;
double itemPrice;
};
void read(menuItemType menuList[], int&);
void showMenu(menuItemType menuList[], int&);
void takeOrder(int, int, menuItemType menulist[]);
int main()
{
int counter = 0;
menuItemType menuList[10];
int order[10] = { 0,0,0,0,0,0,0,0,0,0 };
double totalBill = 0;
double tax = 0;
cout << fixed << setprecision(2) << showpoint;
cout << "Welcome to Hold-ye-Overs, a delightful place to eat with food\nmade from one hundred percent actual food!\n";
read(menuList, counter);
showMenu(menuList, counter);
takeOrder(order[10], counter, menuList);
return 0;
}
void takeOrder(int order[], int counter, menuItemType menuList[])
{
int amount_of_item;
int choice;
bool flag = true;
char orderMore;
while (flag == true)
{
cout << "Please enter the number for the item you would like to have." << endl;
cin >> choice;
cout << "Please enter the number of " << menuList[choice - 1].itemName << "s you would like to order." << endl;
cin >> amount_of_item;
order[choice - 1] = order[choice - 1] + amount_of_item;
cout << "Would you like to order more items? y/n" << endl;
cin >> orderMore;
if (orderMore == 'y' || orderMore == 'Y')
flag = true;
else
flag = false;
}
}
void read(menuItemType menuList[], int& counter)
{
ifstream in;
in.open("menu.txt");
char temp = char();
int i = 0;
while (!in.eof())
{
getline(in, menuList[i].itemName);
in >> menuList[i].itemPrice;
//cout << menuList[i].itemName << " " << menuList[i].itemPrice << endl;
in.get(temp);//to pick up endl after the price
++i;
counter++;
}
in.close();
}
void showMenu(menuItemType menuList[], int& counter)
{
cout << fixed << setprecision(2) << showpoint;
int i = 0;
for (i = 0; i < counter; i++)
{ cout << left << setw(2) << i + 1 << " :" << left << setw(20) << menuList[i].itemName;
cout << right << setw(1) << "$" << left << setw(7) << menuList[i].itemPrice << endl;
}
}
可能重複[什麼是未定義的引用/無法解析的外部符號錯誤,以及如何解決它?](http://stackoverflow.com/questions/1 2573816/what-is-unde-undefined-reference-un-resolved-external-symbol-error-and-how-do-i-fix) –
看看你的'takeOrder'原型和'takeOrder'的實現。看到參數的差異? – PaulMcKenzie
「takeOrder」的聲明和定義之間存在不匹配。 –