gpt4 book ai didi

c++ - 收到基于模板类及其子类函数调用的错误

转载 作者:行者123 更新时间:2023-11-28 08:07:12 24 4
gpt4 key购买 nike

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

非常感谢您的帮助;我们上一个类没有教给我们任何关于继承的知识,但这是这个类的第一个项目,这里也没有教过继承,所以这对我来说都是触手可及的,尽管我设法在谷歌上查找。

最佳答案

您的方法未定义。所以链接器在提示,因为它无法链接到他们的定义。

关于c++ - 收到基于模板类及其子类函数调用的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10082040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com