继承问题

编程入门 行业动态 更新时间:2024-10-21 19:46:43
本文介绍了继承问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以告诉我为什么下面的代码不起作用:

Can someone tell me why the following code doesn''t work:

TestClass.cpp ------------- A级公开:虚拟空读(wchar_t& ch){read(& ch,0,1); } 虚拟空读(wchar_t * buf,int off,int len)= 0; }; B类:公共虚拟A { public: virtual void read(wchar_t * buf,int off,int len){} }; int main(int argc,char * argv []) { wchar_t ch; B myclass; myclass.read(ch); } 我试过两个gcc 2.96和gcc 3.2。我得到: TestClass.cpp:在函数`int main(int,char **)''中: TestClass.cpp:21:没有用于调用`B ::的匹配函数read(wchar_t&)'' TestClass.cpp:14:候选者是:virtual void B :: read(wchar_t *,int,int) TestClass.cpp ------------- class A { public: virtual void read(wchar_t& ch) { read(&ch, 0, 1); } virtual void read(wchar_t* buf, int off, int len) = 0; }; class B : public virtual A { public: virtual void read(wchar_t* buf, int off, int len) {} }; int main(int argc, char* argv[]) { wchar_t ch; B myclass; myclass.read(ch); } I have tried both gcc 2.96 and gcc 3.2. I get: TestClass.cpp: In function `int main(int, char**)'': TestClass.cpp:21: no matching function for call to `B::read(wchar_t&)'' TestClass.cpp:14: candidates are: virtual void B::read(wchar_t*, int, int)

难道不应该从A继承读取(wchar_t& ch)吗?

Shouldn''t B have inherited read(wchar_t& ch) from A?

推荐答案

" ; Victor Chew < VC *** @ post1>在留言中写道 news:bg ********** @ mawar.singnet.sg ... "Victor Chew" <vc***@post1> wrote in message news:bg**********@mawar.singnet.sg... 有人可以告诉我为什么以下代码不起作用: Can someone tell me why the following code doesn''t work: > TestClass.cpp > ------------- A级 {公开:虚拟空读(wchar_t& ch){read(& ch,0 ,1); } 虚拟空读(wchar_t * buf,int off,int len)= 0; }; B类:公共虚拟A { public: virtual void read(wchar_t * buf,int off,int len){} }; int main(int argc,char * argv []) { wchar_t ch; B myclass; myclass.read(ch); } 我已经尝试过gcc 2.96和gcc 3.2。我得到: > TestClass.cpp > ------------- class A { public: virtual void read(wchar_t& ch) { read(&ch, 0, 1); } virtual void read(wchar_t* buf, int off, int len) = 0; }; class B : public virtual A { public: virtual void read(wchar_t* buf, int off, int len) {} }; int main(int argc, char* argv[]) { wchar_t ch; B myclass; myclass.read(ch); } I have tried both gcc 2.96 and gcc 3.2. I get: TestClass.cpp:在函数`int main(int,char **)''中: TestClass.cpp:21:没有用于调用的匹配函数`B :: read(wchar_t&)'' TestClass.cpp:14:候选者是:virtual void B :: read(wchar_t *,int, TestClass.cpp: In function `int main(int, char**)'': TestClass.cpp:21: no matching function for call to `B::read(wchar_t&)'' TestClass.cpp:14: candidates are: virtual void B::read(wchar_t*, int,

int)不应该从A继承read(wchar_t& ch)吗?

int) Shouldn''t B have inherited read(wchar_t& ch) from A?

你的基类函数virtual void read(wchar_t& ch)已被隐藏的 派生类 函数虚拟空读(wchar_t * buf,int off,int len)。

Your base class function virtual void read(wchar_t& ch) has been hidden by the derived class function virtual void read(wchar_t* buf, int off, int len).

" Victor Chew" < VC *** @ post1>在留言中写道 news:bg ********** @ mawar.singnet.sg ... "Victor Chew" <vc***@post1> wrote in message news:bg**********@mawar.singnet.sg... 有人可以告诉我为什么以下代码不起作用: Can someone tell me why the following code doesn''t work: > TestClass.cpp > ------------- A级 {公开:虚拟空读(wchar_t& ch){read(& ch,0 ,1); } 虚拟空读(wchar_t * buf,int off,int len)= 0; }; B类:公共虚拟A { public: virtual void read(wchar_t * buf,int off,int len){} }; int main(int argc,char * argv []) { wchar_t ch; B myclass; myclass.read(ch); } > TestClass.cpp > ------------- class A { public: virtual void read(wchar_t& ch) { read(&ch, 0, 1); } virtual void read(wchar_t* buf, int off, int len) = 0; }; class B : public virtual A { public: virtual void read(wchar_t* buf, int off, int len) {} }; int main(int argc, char* argv[]) { wchar_t ch; B myclass; myclass.read(ch); }

我试过两个gcc 2.96和gcc 3.2。我得到:

I have tried both gcc 2.96 and gcc 3.2. I get:

TestClass.cpp:在函数`int main(int,char **)''中: TestClass.cpp:21:没有用于调用的匹配函数`B :: read(wchar_t&)'' TestClass.cpp:14:候选者是:virtual void B :: read(wchar_t *,int,int) TestClass.cpp: In function `int main(int, char**)'': TestClass.cpp:21: no matching function for call to `B::read(wchar_t&)'' TestClass.cpp:14: candidates are: virtual void B::read(wchar_t*, int, int)

难道不应该从A继承read(wchar_t& ch)吗?

Shouldn''t B have inherited read(wchar_t& ch) from A?

B :: read(wchar_t * buf,int off,int len)隐藏A: :read(wchar_t& ch)。 如果覆盖重载的基类函数, 重新定义完整的函数集。 - ES Kim

B::read(wchar_t* buf, int off, int len) hides A::read(wchar_t& ch). If you override an overloaded base class functions, redefine full set of the functions. -- ES Kim

2003年7月31日星期四11:42:17 + 0800,Victor Chew< vc ** *@post1>写道: On Thu, 31 Jul 2003 11:42:17 +0800, Victor Chew <vc***@post1> wrote: 有人能告诉我为什么下面的代码不起作用: Can someone tell me why the following code doesn''t work: TestClass.cpp --- ---------- A级 {公开:虚拟空读(wchar_t& ch){read(& ch,0,1) ; } 虚拟空读(wchar_t * buf,int off,int len)= 0; }; B类:公共虚拟A { public: 使用A :: read; 虚拟空读(wchar_t * buf,int off,int len){} } ; int main(int argc,char * argv []) { wchar_t ch; B myclass; myclass.read(ch) ; } TestClass.cpp ------------- class A { public: virtual void read(wchar_t& ch) { read(&ch, 0, 1); } virtual void read(wchar_t* buf, int off, int len) = 0; }; class B : public virtual A { public: using A::read; virtual void read(wchar_t* buf, int off, int len) {} }; int main(int argc, char* argv[]) { wchar_t ch; B myclass; myclass.read(ch); }

我试过gcc 2.96和gcc 3.2。我得到:

I have tried both gcc 2.96 and gcc 3.2. I get:

TestClass.cpp:在函数`int main(int,char **)''中: TestClass.cpp:21:没有用于调用的匹配函数`B :: read(wchar_t&)'' TestClass.cpp:14:候选者是:virtual void B :: read(wchar_t *,int,int) TestClass.cpp: In function `int main(int, char**)'': TestClass.cpp:21: no matching function for call to `B::read(wchar_t&)'' TestClass.cpp:14: candidates are: virtual void B::read(wchar_t*, int, int)

不应该从A继承读取(wchar_t& ch)吗?

Shouldn''t B have inherited read(wchar_t& ch) from A?

它有,但没有''使用''它被隐藏的其他阅读。 现在不要问我_为什么有人认为这是明智的。

It has, but without the ''using'' it''s hidden by the other read. Now don''t ask me _why_ someone thought that would be sensible.

更多推荐

继承问题

本文发布于:2023-11-17 02:16:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!