纯虚函数重载的错误:cannot instantiate abstract class due to following members

myfjdthink 2011-04-26 03:54:48
最近在看一本书《数据结构与算法——面向对象的C++设计模式》 里面用类模板的形式讲解了栈,然后在实例化使用的时候碰到了如标题所示的问题,实在找不出问题的原因。只能上来求助了,代码较长。。就发到资源那里了,是整个工程。

源代码:
http://download.csdn.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)
...全文
2223 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
月xxxxx 2013-03-22
  • 打赏
  • 举报
回复
一个问题: 我尝试封装HWND来作为子窗口控件的基类 在CommonControl中我写了这样一句话 virtual bool onCreate(void) = 0; 在TreeControl(继承自CommonControl)中我重写了onCreate函数 bool onCreate(LPCSTR p_hWndClass, LPCSTR p_szCaption, HWND p_hWndParent, HINSTANCE p_hInstance, int32_t p_posx, int32_t p_posy, int32_t p_height, int32_t p_width){} 神奇的是代码编译通过了,我不解 纯虚函数 其子类的实现 可以参数不同?那不就是 函数重载 而不是函数重写?纯虚函数这样也行?
myfjdthink 2011-04-27
  • 打赏
  • 举报
回复
继续追问:“另外put函数的ostream类型名有重定义”这个问题该怎么解决呢?
提示错误:error C2872: 'ostream' : ambiguous symbol。
myfjdthink 2011-04-27
  • 打赏
  • 举报
回复
啊啊啊 不能沉下去啊 ……
myfjdthink 2011-04-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 nth2say 的回复:]

class Object
{
protected:
virtual int CompareTo (Object const&) const = 0;
public:
virtual ~Object ();
virtual bool IsNull () const;
virtual int Compare (Object const&)……
[/Quote]
我在Object的派生类container类里实现了CompareTo 这个纯虚函数,问题解决了。
但是你说的“另外put函数的ostream类型名有重定义”这个问题该怎么解决呢?
提示错误:error C2872: 'ostream' : ambiguous symbol。
nth2say 2011-04-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 myfjdthink 的回复:]

引用 2 楼 howtop2p 的回复:

派生自Object的CompareTo没有实现?


有的
C/C++ code
int Object::Compare (Object const& object) const
{
if (typeid (*this) == typeid (object))
return CompareTo (objec……
[/Quote]

你这个是Compare,他说的是 protected:的CompareTo
nth2say 2011-04-26
  • 打赏
  • 举报
回复
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类型名有重定义
ouyh12345 2011-04-26
  • 打赏
  • 举报
回复
纯虚函数需要重写
myfjdthink 2011-04-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fandh 的回复:]

没有下载,支持的平台不一样?
[/Quote]

VC6.0下编译的。
myfjdthink 2011-04-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 howtop2p 的回复:]

派生自Object的CompareTo没有实现?
[/Quote]

有的
int Object::Compare (Object const& object) const
{
if (typeid (*this) == typeid (object))
return CompareTo (object);
else if (typeid (*this).before (typeid (object)))
return -1;
else
return 1;
}
HowToP2p 2011-04-26
  • 打赏
  • 举报
回复
派生自Object的CompareTo没有实现?
fandh 2011-04-26
  • 打赏
  • 举报
回复
没有下载,支持的平台不一样?

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧