继承和虚函数

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

A级{ 私人: 虚拟空虚my_function(); } 级B:公共A { 私人: void my_function(); } 我是否可以通过 声明它是公共函数来提高classB中my_function的可见性? 答案取决于我如何从classB继承classA (即公开, 受保护,私有)?

解决方案

s写道: A类{私人:虚拟空洞my_function(); } B类:公共A {私人: void my_function(); } 我是否允许通过声明它是公共函数来提高classB中my_function的可见性? 是。 答案取决于我如何从classB继承classA(即 public,protected,private)?

No.

" s" < youshouldbe @家>在消息新闻中写道:3FFDC248.5070204@home ...

A类{私人:虚拟空虚my_function(); } B级:公共A {私人: void my_function(); } 我是否可以通过<增加classB中my_function的可见性声明它是一个公共功能? 当然。您有什么想法可能阻止您? 答案取决于我如何从classB继承classA(即public, protected,private)?

是的 - 如果B使用私有的 继承,你将无法从外部访问它。

2004年1月8日星期四16:08:59 -0500,jeffc写道:

答案取决于我如何从classB继承classA (即公开,保护,私有)?

是的 - 如果B使用私有继承,你将无法从外部访问它。

不,classA将无法访问classB的用户,但这与问题无关。 HTH, M4

class A { private: virtual void my_function(); } class B : public A { private: void my_function(); } Am I allowed to increase the visibility of my_function in classB by declaring it a public function? Does the answer depend on how I inherit classA from classB (i.e. public, protected, private)?

解决方案

s wrote:

class A { private: virtual void my_function(); } class B : public A { private: void my_function(); } Am I allowed to increase the visibility of my_function in classB by declaring it a public function? Yes. Does the answer depend on how I inherit classA from classB (i.e. public, protected, private)?

No.

"s" <youshouldbe@home> wrote in message news:3FFDC248.5070204@home...

class A { private: virtual void my_function(); } class B : public A { private: void my_function(); } Am I allowed to increase the visibility of my_function in classB by declaring it a public function? Of course. What do you have in mind that might be stopping you? Does the answer depend on how I inherit classA from classB (i.e. public, protected, private)?

Yes - you won''t be able to access it externally if B uses private inheritance.

On Thu, 08 Jan 2004 16:08:59 -0500, jeffc wrote:

Does the answer depend on how I inherit classA from classB (i.e. public, protected, private)?

Yes - you won''t be able to access it externally if B uses private inheritance.

No, classA will not be accessable to users of classB, but that is irrelevant for the question. HTH, M4

更多推荐

继承和虚函数

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

发布评论

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

>www.elefans.com

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