2014-04-04 160 views
-2

我試圖編譯我的代碼,並繼續得到他的這個錯誤:LINK2019錯誤,不知道爲什麼

Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class iOrder const &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) referenced in function _main C:\Users\on3m1_000\documents\visual studio 2013\Projects\Assign4\Assign4\a4main.obj Assign4 

我,爲什麼這可能發生的事情完全不清楚。我在這個錯誤中看到的唯一東西就是iOrder,它看起來就像在我的代碼中一樣。如果任何人都可以給我任何想法,爲什麼這會發生很好的事情。

iorder頭:

std::ostream& operator<<(std::ostream& os, const iOrder& order); 

主營:

#include <iostream> 
#include "GS1Prefix.h" 
#include "Order.h" 

#define MAXORDERS 100 
char menu(std::istream& is); 
bool style(std::istream& is, char&); 

int main() { 
    char choice; 
    int noOrders = 0; 
    iOrder* order[MAXORDERS]; 
    Prefix prefix("prefixRanges.txt"); 

    std::cout << "Bookstore Order Processor\n" 
     << "=========================\n"; 

    // process user input 
    do { 
     choice = menu(std::cin); 
     std::cout << std::endl; 
     switch (choice) { 
     case 'P': 
     { 
        EAN ean; 
        if (ean.read(std::cin, prefix)) { 
         int index = -1, created = false; 
         for (int i = 0; i < noOrders && index == -1; i++) 
         if (ean == order[i]->getEAN()) 
          index = i; 
         if (index == -1) 
         if (noOrders < MAXORDERS) { 
          index = noOrders; 
          order[noOrders++] = new Order(ean); 
          created = true; 
         } 
         else 
          std::cerr << "No space for more orders!" << std::endl; 
         if (!order[index]->add(std::cin) && created) 
          delete order[--noOrders]; 
        } 
     } 
      break; 
     case 'S': 
     { 
        EAN ean; 
        if (ean.read(std::cin, prefix)) { 
         int index = -1, created = false; 
         for (int i = 0; i < noOrders && index == -1; i++) 
         if (ean == order[i]->getEAN()) 
          index = i; 
         if (index == -1) 
         if (noOrders < MAXORDERS) { 
          index = noOrders; 
          order[noOrders++] = new SpecialOrder(ean, ""); 
          created = true; 
         } 
         else 
          std::cerr << "No space for more orders!" << std::endl; 
         if (!order[index]->add(std::cin) && created) 
          delete order[--noOrders]; 
        } 
     } 
      break; 
     case 'A': 
     { 
        EAN ean; 
        if (ean.read(std::cin, prefix)) { 
         int index = -1; 
         for (int i = 0; i < noOrders && index == -1; i++) 
         if (ean == order[i]->getEAN()) 
          index = i; 
         if (index != -1) 
          order[index]->add(1); 
         else 
          std::cerr << "No order for " << ean << " found!" << std::endl; 
        } 
     } 
      break; 
     case 'D': 
     { 
        EAN ean; 
        if (ean.read(std::cin, prefix)) { 
         int index = -1; 
         for (int i = 0; i < noOrders && index == -1; i++) 
         if (ean == order[i]->getEAN()) 
          index = i; 
         if (index != -1) 
          order[index]->receive(std::cin); 
         else 
          std::cerr << "No order for " << ean << " found!" << std::endl; 
        } 
     } 
      break; 
     case 'F': 
     { 
        char s; 
        if (style(std::cin, s)) 
        for (int i = 0; i < noOrders; i++) 
         order[i]->getEAN().style(s); 
     } 
      break; 
     case 'V': 
      std::cout << "    EAN Ordered Delivered Instructions\n"; 
      std::cout << "--------------------------------------------------\n"; 
      for (int i = 0; i < noOrders; i++) { 
       std::cout << *order[i] << std::endl; 
      } 
      break; 
     } 
    } while (choice != 'Q'); 

    std::cout << "\nSigning off ... " << std::endl; 
    // deallocate order memory 
    for (int i = 0; i < noOrders; i++) 
     delete order[i]; 
} 

// menu prompts for and accepts an option selection from standard input and 
// returns the character identifying the selected option 
// 
char menu(std::istream& is) { 
    char c; 
    int ok = false; 

    std::cout << '\n'; 
    std::cout << "Please select from the following options :\n"; 
    std::cout << " P - Place an order with a publisher\n"; 
    std::cout << " S - Place a special order with a publisher\n"; 
    std::cout << " A - Add one copy to an existing order\n"; 
    std::cout << " D - Record a delivery from a publisher\n"; 
    std::cout << " F - Change output style\n"; 
    std::cout << " V - View status of books on order\n"; 
    std::cout << " Q - Quit\n"; 
    do { 
     std::cout << " Your selection : "; 
     c = ' '; 
     is.get(c); 
     if (c >= 'a' && c <= 'z') 
      c -= 'a' - 'A'; 
     if (is.fail()) { 
      is.clear(); 
      is.ignore(2000, '\n'); 
      std::cerr << " Invalid input. Try again.\n"; 
     } 
     else if (c == '\n') { 
      ; // no input - try again 
     } 
     else if (c != 'P' && c != 'S' && c != 'A' && c != 'D' && c != 'V' 
      && c != 'Q' && c != 'F') { 
      is.ignore(2000, '\n'); 
      std::cerr << " Invalid Character. Try again.\n"; 
     } 
     else if (is.get() != '\n') { 
      is.ignore(2000, '\n'); 
      std::cerr << " Trailing Characters. Try Again.\n"; 
     } 
     else if (c == 'P' || c == 'S' || c == 'A' || c == 'D' || c == 'V' 
      || c == 'Q' || c == 'F') 
      ok = true; 
    } while (ok == 0); 

    return c; 
} 

// style prompts for and accepts the style from input stream is 
// 
bool style(std::istream& is, char& s) { 
    bool rc = false, ok = false; 
    char c; 
    do { 
     std::cout << " EAN Style ('-', ' ', '\\n' or '0' to quit) : "; 
     c = ' '; 
     is.get(c); 
     if (is.fail()) { 
      is.clear(); 
      is.ignore(2000, '\n'); 
      std::cerr << " Invalid input. Try again.\n"; 
     } 
     else if (c != '-' && c != ' ' && c != '\n' && c != '0') { 
      is.ignore(2000, '\n'); 
      std::cerr << " Invalid Character. Try again.\n"; 
     } 
     else if (c == '0') { 
      if (is.get() != '\n') { 
       is.ignore(2000, '\n'); 
       std::cerr << " Trailing Characters. Try Again.\n"; 
      } 
      else 
       ok = true; 
     } 
     else if (c == '\n') { 
      ok = true; 
      s = '\0'; 
      rc = true; 
     } 
     else if (is.get() != '\n') { 
      is.ignore(2000, '\n'); 
      std::cerr << " Trailing Characters. Try Again.\n"; 
     } 
     else if (c == '-' || c == ' ') { 
      ok = true; 
      s = c; 
      rc = true; 
     } 
    } while (!ok); 

    return rc; 
} 
+0

爲什麼你不減少代碼來簡化問題嗎? – cbel

+0

將'#include「ean.h」'從'iorder.h'移動到'iorder.cpp',並且不在類的頭文件中包含任何文件。 ** std :: ostream&operator <<(std :: ostream&os,const iOrder&order)的實現在哪裏?' –

+0

請繼續刪除代碼,直到找到可以重現問題的最小代碼。 – user93353

回答

1

您聲明和使用該運營商:

std::ostream& operator<<(std::ostream& os, const iOrder& order); 

,但你有沒有編寫任何代碼爲它(或因爲它不在所示的代碼中)

+0

謝謝!這是問題,修復了錯字,現在它工作正常。 – onemic

相關問題