保护继承(protected)
保护继承与私有继承相似,基类成员对其对象的可见性与一般类及其对象的可见性相同,public成员可见,其他成员不可见。
基类成员对派生类的可见性,对派生类来说,基类的public和protected成员是可见的:基类的public成员和protected成员都作为派生类的protected成员,并且不能被这个派生类的子类所访问;基类的private成员是不可见的:派生类不可访问基类中的private成员。
基类成员对派生类对象的可见性对派生类对象来说,基类的所有成员都是不可见的。
所以,在保护继承时,基类的成员也只能由直接派生类访问,而无法再向下继承。
上面这个是不是有问题
During prototyped inheritance, both public members and protected members of the base class can be accessed by subclasses of the derived class. There is indeed a problem with this.
The simplest way to verify is to practice.
I don’t understand the meaning of such a paragraph. If it is a book, I suggest you read it in another book
The visibility of inheritance is reduced, that is, protected inheritance will turn public into protected, and protected and private will remain unchanged.
As long as the derived class of the base class does not inherit privately, the derived class of the derived class can also access the non-private properties of the base class
I also want to ask this question
Part of the code of %%%C++ data structure
class const_iterator
The following error occurs when compiling with dev-C++:
The class iterator inherits from const_iterator, but it seems that the protected content in const_iterator cannot be called in iterator?
This code is excerpted from "Data Structure and Algorithm Analysis C++ Description" third edition, written by Mark Allen Weiss.