0
1>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::getfirst(int &)" (?getfirst@?$LinkedSortedList@H@@UAE_NAAH@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall LinkedSortedList<int>::clear(void)" (?clear@?$LinkedSortedList@H@@UAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall LinkedSortedList<int>::print(void)const " (?print@?$LinkedSortedList@H@@UBEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::insert(int)" (?insert@?$LinkedSortedList@H@@UAE_NH@Z) referenced in function _main
1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::find(int)const " (?find@?$LinkedSortedList@H@@UBE_NH@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall LinkedSortedList<int>::size(void)const " (?size@?$LinkedSortedList@H@@UBEHXZ)
1>c:\users\chris\documents\visual studio 2010\Projects\lab0\Debug\lab0.exe : fatal error LNK1120: 6 unresolved externals

これは、コードをコンパイルしようとしたときに受け取るものです。私はそれを(私が信じている)コードのこのセクションに絞り込みました:

#ifndef _LinkedSortedListClass_
#define _LinkedSortedListClass_


    #include "LinkedNode.h"
    #include "SortedList.h"

    template <class Elm>
    class LinkedSortedList: public SortedList<int> {    
    public:

        void clear();

        bool insert(Elm newvalue);

        bool getfirst(Elm &returnvalue);

        void print() const;

        bool find(Elm searchvalue) const;

        int size() const;

    private:
            LinkedNode<Elm>* head;
    };

    #endif

これは、必要な場合に備えて、SortedList の子クラスです。

#ifndef _SortedListClass_
#define _SortedListClass_

template <class Elm> class SortedList {
public:

  // -------------------------------------------------------------------
  // Pure virtual functions -- you must implement each of the following
  // functions in your implementation:
  // -------------------------------------------------------------------

  // Clear the list.  Free any dynamic storage.
  virtual void clear() = 0;          

  // Insert a value into the list.  Return true if successful, false
  // if failure.
  virtual bool insert(Elm newvalue) = 0;

  // Get AND DELETE the first element of the list, placing it into the
  // return variable "value".  If the list is empty, return false, otherwise
  // return true.
  virtual bool getfirst(Elm &returnvalue) = 0;

  // Print out the entire list to cout.  Print an appropriate message
  // if the list is empty.  Note:  the "const" keyword indicates that
  // this function cannot change the contents of the list.
  virtual void print() const = 0;

  // Check to see if "value" is in the list.  If it is found in the list,
  // return true, otherwise return false.  Like print(), this function is
  // declared with the "const" keyword, and so cannot change the contents
  // of the list.
  virtual bool find(Elm searchvalue) const = 0;

  // Return the number of items in the list
  virtual int size() const = 0;
};

#endif

助けてくれてありがとう。私たちの最後のクラスでは継承について何も教えてくれませんでしたが、これはこのクラスのプロジェクト #1 であり、ここでも継承について教えられていません。

4

2 に答える 2

1

メソッドが定義されていません。そのため、リンカーは定義にリンクできないため、不平を言っています。

于 2012-04-10T01:39:29.890 に答える
0

関数の定義をヘッダー ファイルに配置すると、役立つ場合があります。これにより、コンパイラがこれらの外部シンボルを解決しやすくなります。

これが役立つことを願っています。

よろしく、フィリネーター

于 2016-03-25T14:02:15.683 に答える