이것은 구조체 배열을 동적으로 만들어야하는 프로젝트이다. 이 오류가 무엇을 의미하는지 또는 내 코드가 무엇이 잘못된 것인지 전혀 알 수 없습니다.동적 할당. 이 오류가 무엇을 의미하는지 모르겠다.
여기에 제시된 조언을 바탕으로 대부분의 문제가 해결되었습니다. 다음은 나머지 오류의 간단한 목록입니다.
/tmp/ccdjbURO.o: In function `main':
assignment8.cpp:(.text+0x5a): undefined reference to `getData(menuItemType&, int&, std::basic_ifstream<char, std::char_traits<char> >&)'
assignment8.cpp:(.text+0x116): undefined reference to `showMenu(menuItemType, int)'
assignment8.cpp:(.text+0x1a5): undefined reference to `showMenu(menuItemType, int)'
assignment8.cpp:(.text+0x29f): undefined reference to `makeSelection(int&, int, int)'
assignment8.cpp:(.text+0x2eb): undefined reference to `printCheck(menuItemType, int, int)'
collect2: error: ld returned 1 exit status
다음은 필자의 함수 프로토 타입과 정의입니다. 프로토 타입과 정의 표제의 함수 시그니처와 내 프로그램 본문에있는 함수 호출의 형식이 다른 점은 없습니다.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
};
const double TAX = 0.05;
const string FILE_NAME = "Ch9_Ex5Data.txt";
int getData(menuItemType&, int&, ifstream);
int makeSelection(int&, int, int);
void showMenu(menuItemType, int);
void printCheck(menuItemType, int, int);
void getInt(int&);
void getChar(char&);
//********************************************************************************
//* getData
//********************************************************************************
int getData(menuItemType* &menuList, int& listSize, ifstream& inFile)
{
inFile.open("Ch9_Ex5Data.txt");
inFile >> listSize;
if (inFile.fail())
return -1;
menuList = new menuItemType[listSize];
for(int i = 0; i < listSize; i++)
{
getline(inFile, menuList[i].menuItem);
inFile >> menuList[i].menuPrice;
if (inFile.fail())
return -1;
break;
}
122,1 47%
return 1;
}
//********************************************************************************
//* makeSelection
//********************************************************************************
int makeSelection(int* &orderList, int quantity, int index)
{
if ((orderList[index] + quantity) < 0)
{
cout << "Quantity selected makes total number ordered less than 0"
<< endl << endl;
return 1;
}
else
{
orderList[index] = orderList[index] + 1;
return -1;
}
}
//********************************************************************************
//* showMenu
//********************************************************************************
void showMenu(menuItemType *menuList, int listSize)
{
cout << fixed << showpoint << setprecision(2) << endl << endl
<< "------Today's Menu------" << endl;
for(int i = 0; i < listSize; i++)
{
cout << left << setw(18) << menuList[i].menuItem << "$ "
<< right << setw(4) << menuList[i].menuPrice << endl;
}
cout << "------------------------"
<< endl << endl;
}
//********************************************************************************
//* printCheck
//********************************************************************************
void printCheck(menuItemType *menuList, int *orderList, int listSize)
{
int taxDue = 0;
int amntDue = 0;
cout << fixed << showpoint << setprecision(2) << endl << endl
<< "------Your Reciept------" << endl;
for (int i = 0; i < listSize; i++)
{
if (orderList[i] > 0)
{
cout << left << setw(2) << orderList[i] << " "
<< setw(15) << menuList[i].menuItem
<< right << setw(5) << (orderList[i] * menuList[i].menuPrice)
<< endl;
amntDue += (orderList[i] * menuList[i].menuPrice);
}
}
210,1 73%
taxDue = amntDue * TAX;
amntDue = amntDue * (1 + TAX);
cout << endl << right << setw(17) << "Tax: $ "
<< setw(7) << taxDue
<< endl << right << setw(17) << "Amount Due: $ "
<< setw(7) << amntDue
<< endl
<< "------------------------" << endl << endl;
}
187,0-1 64%
당신이 ifstream을 복사 할 수 있으며, 하나의 getline (IStream을 &, 문자열 &)'와'의 getline (문자열)'라는 함수가 없다'이후이 같은로 교체 어디에서 그 줄을 가져야하는지. – PeterT