关于继承的问题 [英] question about kind of inheritance

查看:95
本文介绍了关于继承的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,你好。我有一个问题

如果我们没有定义继承的类型(公共或私人)

默认是继承私有?

例如,如果我写了

  class  A 
{
};
class B:A
{
};



类似

  class  A 
{
};
class B: private A
{
};



是真的吗?

请帮帮我。谢谢

解决方案

就像未指定的类成员一样,如果在声明继承时未指定访问权限,则默认为private。



所以是的,你的两个例子是等价的。

我个人更喜欢看后一种形式,就像我更喜欢看到成员指定的访问权限一样一个班级。


hello friends. i have a question
if we don't define the kind of inheritance(public or private)
by default is the inheritance private?
for example if i write

class A
{ 
};
class B:A
{
};


is similar to

class A
{
};
class B:private A
{
};


is it true?
please help me. thanks

解决方案

Just like with unspecified member of a class, if you do not specify the access when you declare the inheritance it defaults to private.

So yes, your two examples are equivalent.
I'd personally prefer to see the latter form though, just as I prefer to see the access specified for members of a class.


这篇关于关于继承的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆