默认继承访问说明符 [英] Default inheritance access specifier

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

问题描述

如果我有两个类 A B ,使得 B 继承 A 如下:

If I have for example two classes A and B, such that class B inherits A as follows:

B类:public A

class B: public A

在这种情况下,我会执行 public 继承。

In this case, I'm doing public inheritance.

如果我写如下代码:

B类:A

我将在这里做什么类型的继承(即public)?换句话说,什么是默认访问说明符?

What type of inheritance will I be doing here (i.e; public)? In other words, what is the default access specifier?

这里只是一个侧面的问题。我是否调用上一行代码语句?特别是我记得我在 C ++ Without Fear:A Beginner's Guide that Make You Feel Smart 中看到语句是以;

Just a side question here. Do I call the previous line of codes statements? Especially that I remember I read in the C++ Without Fear: A Beginner's Guide That Makes You Feel Smart book that statements are that that end with ;. What do you think about that?

感谢。

推荐答案

一个小的除了所有现有的答案:继承的默认类型取决于继承类型(B),而不是正在继承的(A)。例如:

Just a small addition to all the existing answers: the default type of the inheritance depends on the inheriting type (B), not on the one that is being inherited (A). For example:

class A {};
struct B: /* public */ A {};

struct A {};
class B: /* private */ A {};

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

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