2013-06-18 5 views
-1

나는 나를 미치게 만드는 몇 가지 링크 오류가 있습니다. 이 테스트를 제외한 모든 테스트가 작동합니다. 이 하나는 해결되지 않은 외부 기호에 문제가 있음을 나타냅니다. 제 3의 테스트를 제외한 모든 테스트가 제대로 작동한다는 것은 제게 의미가 없습니다. 귀하의 구현 int의를 사용하고 있지만 main에서 통화가 bankAccount 값 기능을 찾고 있습니다 있도록LNK 2019 오류

1> All outputs are up-to-date. 
    1>test11c.obj : error LNK2019: unresolved external symbol "public: class bankAccount __thiscall bag::currentItem(void)const " ([email protected]@@[email protected]@XZ) referenced in function _main 
    1>test11c.obj : error LNK2019: unresolved external symbol "public: void __thiscall bag::add(class bankAccount)" ([email protected]@@[email protected]@@Z) referenced in function _main 
    1>C:\Users\Desktop\stats\bagObject\Debug\bagObject.exe : fatal error LNK1120: 2 unresolved externals 
    1> 

    // 11C Test bag.sort (answer in bag.cpp) 
    #include <iostream> 
    using namespace std; 

    #include "COMPFUN.H"// For decimals 
    #include "BACCOUNT.H"// Must include baccount before the typedef 

    typedef bankAccount BAG_ELEMENT_TYPE; 
    #include "bag.h" // For the bag class 

    int main() 
    { 
     bag account; 

     account.add(bankAccount("Mellisa", 400)); 
     account.add(bankAccount("Miguel", 200)); 
     account.add(bankAccount("Bob", 300)); 
     decimals(cout, 2); 
     account.sort(); 
     bankAccount anAcct; 
     for(account.first(); ! account.isDone(); account.next()) 
     { 

account= account.currentItem();  // Output: 
     cout.width(8);      // 300.00 Bob 
     cout << anAcct.balance();    // 400.00 Mellisa 
     cout << " " << anAcct.name() << endl; // 200.00 Miguel 
     } 

     return 0; 
    } 

    //------------------------------------------------------------------ 
    // INTERFACE FILE: baccount.h 
    // 
    // Defines class bankAccount 
    // Declares the relational operators so bankAccount objects 
    // can be stored in standard containers such as list 
    // 
    //------------------------------------------------------------------- 
    // SAFEGUARDS AND INCLUDES 
    #ifndef BACCOUNT_H // Avoid redeclaring class bankAccount. 
    #define BACCOUNT_H // This code is compiled only once 
    #include <string> // for class string 
    using namespace std; // avoid having to write std:: as in std::string 

    /////////////////////////////////////////// 
    /////// class bankAccount defintion /////// 
    /////////////////////////////////////////// 

    class bankAccount { 
    public: // class member functions 

    //--constructors 
     bankAccount(); 

     bankAccount(string initName, double initBalance); 
     // post: A bankAccount with two arguments when called like this: 
     //  bankAccount anAcct("Hall", 100.00); 

    //--modifiers 

     void deposit(double depositAmount); 
     // post: depositAmount is credited to this object's balance 

     void withdraw(double withdrawalAmount); 
     // post: withdrawalAmount is debited from this object's balance 

    //--accessors 

     double balance() const; 
     // post: return this account's current balance 

     string name() const; 
     // post return the account name 

    private: 
     string my_name; // Uniquely identify an object 
     double my_balance; // Store the current balance (non-persistent) 
    }; 

    //--Auxilliary functions 

    // With these two functions, bankAccount objects can be 
    // sorted and searched by the standard algorithms 
    bool operator < (const bankAccount & left, const bankAccount & right); 
    bool operator == (const bankAccount & left, const bankAccount & right); 
    bool operator != (const bankAccount & left, const bankAccount & right); 
    bool operator <= (const bankAccount & left, const bankAccount & right); 
    bool operator > (const bankAccount & left, const bankAccount & right); 
    bool operator >= (const bankAccount & left, const bankAccount & right); 

    #endif // ifndef BACCOUNT_H 

.CPP FILE 

    #include <iostream> 
    #include <vector> 
    #include <cctype> 
    #include <string> 
    #include "BACCOUNT.H" 
    #include "COMPFUN.H" 
    using namespace std; 

    typedef int BAG_ELEMENT_TYPE; 
    #include "bag.h" 

    //--constructors 


    bag::bag(int initCapacity) 
     // pre: initCapacity >= 1 
     // post: size of this bag is bag to 0 with the capacity 
     //  to store initCapacity BAG_ELEMENT_TYPE objects 
     { 
      my_size = 0; my_index = 0; 
     my_capacity = initCapacity; 
     my_element.resize(my_capacity); 

     } 
    //--modifiers 
     int bag::occurrencesOf(BAG_ELEMENT_TYPE matchValue) 
    { 
     int results = 0; 
     for (first(); !isDone(); next()) 
     { 
     if (matchValue == currentItem()) 
     { 
       results++; 
     } 
     } 
     return results;   
    } 

     void bag::add(BAG_ELEMENT_TYPE newElement) 
     // post: Add newElement to this bag and increase 
     //  the size of this bag object increased by +1. 

    //  Note: If capacity < size, the bag doubles it capacity 
     { if (my_size >= my_capacity) 
     { 
      my_element.resize(2 * my_capacity); 
     }  my_element[my_size] = newElement; 
      my_size++; 


     } 
     bool bag::remove(BAG_ELEMENT_TYPE removalCandidate) 
     // post: If found, removalCandidate is removed from this bag. 
     { 
      int subscript =0; 
     while((subscript < my_size) && (my_element[subscript] != removalCandidate)) 
     { 
     subscript++; 
     } 
    if(subscript == my_size) 
     {// removalCandidate not found 
     return false; 
     } 
     else 
     { // move last element to removalCandidate's spot 
     my_element[subscript]= my_element[my_size-1]; 
     // and then decreaase size by one 
     my_size--; 
     return true; 
     } 

     } 

     void bag::sort() 
     // post: sort in ascending order 
     { 
      BAG_ELEMENT_TYPE Bag2; 
     for(int top = 0; top < my_size-1; top++) 
     { 
     for(int j = top+1; j < my_size; j++) 
     {if(my_element[j] < my_element[top]) 
     { 
      Bag2 = my_element[top]; 
      my_element[top] = my_element[j]; 
      my_element[j] = Bag2; 
     } 
     } 
     } 
     } 
    //--accessors 

     int bag::capacity() const 
     // post: return the maximum number of elements that could be stored in this bag 
     { 
      return my_capacity; 
     } 
     int bag::size() const 
     // post: return the number of elements that are currently in this bag 
     //  the number of objects added but not removed. 
     { 
      return my_size; 
     } 
     bool bag::isEmpty() const 
     // post: Returns true if there are zero items in the bag. 
     //  Returns false if there is one more added elements 
     { if(my_size !=0) 
     return my_size==0; 
     } 
    //--iterator functions 

     void bag::first() const 
     // post: my_index points to the first item 

     // Cast away const so this appears to not modify the object 
     // This is the only situation this trick should be used to subvert the meaning of const 
     //((bag*)this)->my_index = 0; 
     { 
      if(my_size >= 0) 
       ((bag*)this)->my_index = 0; 

     } 
     void bag::next() const 
     // post: my_index points to the next item 

     // Cast away const so this appears to not modify the object 
     // This is the only situation this trick should be used to subvert the meaning of const 
     // ((bag*)this)->my_index++; 
     { 
      ((bag*)this)->my_index++; 
     } 
     bool bag::isDone() const 
     // post: Returns true if the collection has been traversed 
     { 
      return my_index >= my_size; 
     } 

    BAG_ELEMENT_TYPE bag::currentItem() const 
     // pre: ! isDone && my_size > 0 
     // post: Returns the item pointed to by the my_index 

     { 
      return my_element[my_index]; 
     } 


Bag.h 

    #ifndef BAG_H 
    #define BAG_H 
    #include <iostream> 
    #include "BACCOUNT.H" 
    #include "COMPFUN.H" 
    #include <vector> 
    using namespace std; 

    const int DEFAULT_INITIAL_BAG_CAPACITY = 16; 

    class bag { 
    public: 

    //--constructors 
     bag(); 
     // post: Size of this bag is 0. 
     //  Initial capacity == DEFAULT_INITIAL_BAG_CAPACITY 

     bag(int initCapacity); 
     // pre: initCapacity >= 1 
     // post: size of this bag is bag to 0 with the capacity 
     //  to store initCapacity BAG_ELEMENT_TYPE objects 

    //--modifiers 
     int occurrencesOf(BAG_ELEMENT_TYPE matchValue); 
     void add(BAG_ELEMENT_TYPE newElement); 
     // post: Add newElement to this bag and increase 
     //  the size of this bag object increased by +1. 

    //  Note: If capacity < size, the bag doubles it capacity 

     bool remove(BAG_ELEMENT_TYPE removalCandidate); 
     // post: If found, removalCandidate is removed from this bag. 

     void sort(); 
     // post: sort in ascending order 

    //--accessors 



     int capacity() const; 
     // post: return the maximum number of elements that could be stored in this bag 

     int size() const; 

     bool isEmpty() const; 
     // post: Returns true if there are zero items in the bag. 
     //  Returns false if there is one more added elements 



     void first() const; 
     // post: my_index points to the first item 

     // Cast away const so this appears to not modify the object 
     // This is the only situation this trick should be used to subvert the meaning of const 
     //((bag*)this)->my_index = 0; 

     void next() const; 
     // post: my_index points to the next item 

     // Cast away const so this appears to not modify the object 
     // This is the only situation this trick should be used to subvert the meaning of const 
     // ((bag*)this)->my_index++; 

     bool isDone() const; 
     // post: Returns true if the collection has been traversed 

     BAG_ELEMENT_TYPE currentItem() const; 
     // pre: ! isDone && my_size > 0 
     // post: Returns the item pointed to by the my_index 

    private: 
    int occurrencesOf(BAG_ELEMENT_TYPE) const; 
     int my_size; 
     int my_capacity; 
     int my_index; // an internal cursor for iterating over all elements 
     vector <BAG_ELEMENT_TYPE> my_element; 

    }; 

    #endif // #ifndef BAG_H 
+0

bag.h에 들어있는 것은 무엇입니까? –

+0

내가 작성한 가방 클래스의 헤더 파일입니다. –

+0

나는 그것을 제거하고 여전히 같은 문제가 .... 뭔가 bankaccount.h 파일에 맞지 않다 ... 아니면 적어도 내 가정의 –

답변

0

당신은 당신의 CPP 파일에 intBAG_ELEMENT_TYPE 세트가 있습니다. 일치시킬 함수 서명이 필요합니다.

0
  1. BAG_ELEMENT_TYPE 유형에는 두 개의 다른 typedef가 있습니다. 다른 사람들이 이미 언급했듯이이를 고쳐야합니다.
  2. "add"및 "currentItem"메서드는 bag.cpp 파일에 정의 된 주 파일에서 사용되기 때문에 링커는 실제로 불만을 제기하지만 bag.h 파일에서는 선언되지 않습니다. 수업 내에서 추가해야합니다.

희망 하시겠습니까?

관련 문제