继承和虚函数 [英] Inheritance and virtual functions
问题描述
A级{
私人:
虚拟空虚my_function();
}
级B:公共A {
私人:
void my_function();
}
我是否可以通过
声明它是公共函数来提高classB中my_function的可见性?
答案取决于我如何从classB继承classA (即公开,
受保护,私有)?
s写道:
< blockquote class =post_quotes> 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使用私有的
继承,你将无法从外部访问它。
< blockquote> 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
这篇关于继承和虚函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!