纯虚函数重载的异常:cannot instantiate abstract class due to following members
纯虚函数重载的错误:cannot instantiate abstract class due to following members
最近在看一本书《数据结构与算法——面向对象的C++设计模式》 里面用类模板的形式讲解了栈,然后在实例化使用的时候碰到了如标题所示的问题,实在找不出问题的原因。只能上来求助了,代码较长。。就发到资源那里了,是整个工程。
源代码:
http://download.****.net/source/3227340
下面是错误提示:
:\myfjdthink\dsexp5\datatem\test.cpp(8) : error C2259: 'StackAsArray' : cannot instantiate abstract class due to following members:
d:\myfjdthink\dsexp5\datatem\stack_queue.h(25) : see declaration of 'StackAsArray'
d:\myfjdthink\dsexp5\datatem\test.cpp(8) : warning C4259: 'int __thiscall Object::CompareTo(const class Object &) const' : pure virtual function was not defined
d:\myfjdthink\dsexp5\datatem\container_iterator.h(16) : see declaration of 'CompareTo'
d:\myfjdthink\dsexp5\datatem\test.cpp(8) : error C2259: 'StackAsArray' : cannot instantiate abstract class due to following members:
d:\myfjdthink\dsexp5\datatem\stack_queue.h(25) : see declaration of 'StackAsArray'
d:\myfjdthink\dsexp5\datatem\test.cpp(8) : warning C4259: 'int __thiscall Object::CompareTo(const class Object &) const' : pure virtual function was not defined
d:\myfjdthink\dsexp5\datatem\container_iterator.h(16) : see declaration of 'CompareTo'
d:\myfjdthink\dsexp5\datatem\container_iterator.h(127) : error C2872: 'ostream' : ambiguous symbol
d:\myfjdthink\dsexp5\datatem\test.cpp(9) : see reference to class template instantiation 'Wrapper<int>' being compiled
Error executing cl.exe.
DataTem.exe - 3 error(s), 0 warning(s)
------解决方案--------------------
派生自Object的CompareTo没有实现?
------解决方案--------------------
纯虚函数需要重写
------解决方案--------------------
class Object
{
protected:
virtual int CompareTo (Object const&) const = 0;
public:
virtual ~Object ();
virtual bool IsNull () const;
virtual int Compare (Object const&) const;
virtual HashValue Hash () const = 0;
virtual void Put (ostream&) const = 0;
};
object类CompareTo 这个纯虚函数未实现
另外put函数的ostream类型名有重定义
最近在看一本书《数据结构与算法——面向对象的C++设计模式》 里面用类模板的形式讲解了栈,然后在实例化使用的时候碰到了如标题所示的问题,实在找不出问题的原因。只能上来求助了,代码较长。。就发到资源那里了,是整个工程。
源代码:
http://download.****.net/source/3227340
下面是错误提示:
:\myfjdthink\dsexp5\datatem\test.cpp(8) : error C2259: 'StackAsArray' : cannot instantiate abstract class due to following members:
d:\myfjdthink\dsexp5\datatem\stack_queue.h(25) : see declaration of 'StackAsArray'
d:\myfjdthink\dsexp5\datatem\test.cpp(8) : warning C4259: 'int __thiscall Object::CompareTo(const class Object &) const' : pure virtual function was not defined
d:\myfjdthink\dsexp5\datatem\container_iterator.h(16) : see declaration of 'CompareTo'
d:\myfjdthink\dsexp5\datatem\test.cpp(8) : error C2259: 'StackAsArray' : cannot instantiate abstract class due to following members:
d:\myfjdthink\dsexp5\datatem\stack_queue.h(25) : see declaration of 'StackAsArray'
d:\myfjdthink\dsexp5\datatem\test.cpp(8) : warning C4259: 'int __thiscall Object::CompareTo(const class Object &) const' : pure virtual function was not defined
d:\myfjdthink\dsexp5\datatem\container_iterator.h(16) : see declaration of 'CompareTo'
d:\myfjdthink\dsexp5\datatem\container_iterator.h(127) : error C2872: 'ostream' : ambiguous symbol
d:\myfjdthink\dsexp5\datatem\test.cpp(9) : see reference to class template instantiation 'Wrapper<int>' being compiled
Error executing cl.exe.
DataTem.exe - 3 error(s), 0 warning(s)
------解决方案--------------------
派生自Object的CompareTo没有实现?
------解决方案--------------------
纯虚函数需要重写
------解决方案--------------------
class Object
{
protected:
virtual int CompareTo (Object const&) const = 0;
public:
virtual ~Object ();
virtual bool IsNull () const;
virtual int Compare (Object const&) const;
virtual HashValue Hash () const = 0;
virtual void Put (ostream&) const = 0;
};
object类CompareTo 这个纯虚函数未实现
另外put函数的ostream类型名有重定义