2014-04-24 2 views
0

이것은 구조체 배열을 동적으로 만들어야하는 프로젝트이다. 이 오류가 무엇을 의미하는지 또는 내 코드가 무엇이 잘못된 것인지 전혀 알 수 없습니다.동적 할당. 이 오류가 무엇을 의미하는지 모르겠다.

여기에 제시된 조언을 바탕으로 대부분의 문제가 해결되었습니다. 다음은 나머지 오류의 간단한 목록입니다.

/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% 
+0

당신이 ifstream을 복사 할 수 있으며, 하나의 getline (IStream을 &, 문자열 &)'와'의 getline (문자열)'라는 함수가 없다'이후이 같은로 교체 어디에서 그 줄을 가져야하는지. – PeterT

답변

0

오류는 비우호하지만 문제는 간단합니다.

당신은 ifstream

int getData(menuItemType* &menuList, int& listSize, ifstream inFile)

에서 암시 적으로 그것의 사본을 시도 값에 의해 전달합니다.

나는 istreamostream을 복사 할 수 없다고 생각합니다. 참조로 전달해야합니다.

또한 @PeterT가 주석에서 말한대로 getline 버전을 호출하려고합니다. 두 기본 버전은 모두 inputstring을 인수로 사용합니다.

+0

그것은 대부분의 오류를 cledared. 나는 gettl과 함께 istream 변수를 인수로 포함하는 것을 뻔뻔스럽게 잊어 버렸다는 것을 알았다. 이제 짧은 오류 목록 만 남았습니다.하지만이 오류가 무엇을 의미하는지 알지 못합니다. 오류는 함수에 대한 정의되지 않은 참조에 대해 이야기하지만 줄 번호는 제공하지 않습니다. 이것들이 나타내는 것은 무엇입니까? 오류는 다음과 같습니다. – user3569354

+0

/tmp/ccdjbURO.o : 함수 main에서 : assignment8.cpp :(. 텍스트 + 0x5a) : getData (menuItemType &, int & std :: basic_ifstream >) ' assignment8.cpp :(. 텍스트 + 0x116) :'showMenu (menuItemType, int) '에 대한 정의되지 않은 참조 assignment8.cpp :(. 텍스트 + 0x1a5) :'showMenu (menuItemType, int) '에 대한 정의되지 않은 참조 assignment8 'printCheck (menuItemType, int, int)'에 대한 정의되지 않은 참조 collect2 : .cpp :(. 텍스트 + 0x29f) : 'makeSelection (int 및 int, int)'에 대한 정의되지 않은 참조 assignment8.cpp :(텍스트 + 0x2eb) : 오류 : ld가 1을 반환했습니다. 종료 상태 – user3569354

+0

이것은 링커 오류입니다. 당신은 객체들을 그 함수들과 링크시키지 않았습니다. 그들에 대한 정의를 제공해야합니다. 그것은 비록 다른 문제입니다. – luk32

0

전달 선언은 정의와 다릅니다. 자연스럽게 프로그램을 알려줄 필요가

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&); 
관련 문제