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

如果您将函数的定义放在头文件中,也许会有所帮助。这使编译器更容易解析这些外部符号。

我希望这将有所帮助。

问候, Philinator

于 2016-03-25T14:02:15.683 回答