Given a hierarchy (inheritance system), one class student is inherited from a class person public. When it is necessary to call a function successfully, students needs to be implicitly transformed to persons, it demonstrates this to the compiler.
Item 39: exercise caution when using private inheritance (private inheritance)
By Scott Meyers
Translator: fatalerror99 (itepub's nirvana)
Release: http://blog.csdn.net/fatalerror99/
Item 32 discusses how C ++ regards public inheritance (Public
Reading Notes Objective c ++ Item 39 use private inheritance wisely and cautiously, using tiveprivate1. Introduction to private inheritance
Item 32 indicates that C ++ treats public inheritance as a "is-a" relationship. Consider an inheritance
What is private inheritance? When I was studying at school, I had never studied such a thing carefully. Later, I used the boost library in my work to learn about it. If we say that most inheritance protection is for language integrity, private
About C ++ private inheritance and c private inheritance
Many C ++ programmers have never used private inheritance to design their classes. Indeed, if private inheritance is used but public inheritance is used, the implementation of program
Use private inheritance wisely
Clause 35 states that C ++ regards public inheritance as "a" relationship. It is confirmed through this example: In a class hierarchy, student class inherits from the public class of person, in order to make a
C + + (in addition to member variables) has another way to implement has-a relationships-private inheritance.With private inheritance, both the public and the protected members of the base class become private members of the derived class.(If you
Many C + + programmers never use private inheritance to design their classes. Indeed, if it is a place where private inheritance is used, it has no effect on the implementation of the function of the program. But this misuse is a dislocation of the
Private inheritance you do not knowThere are many inheritance methods in the C ++ class, and the most common method we use in software design and code writing is public inheritance, which is rarely used in private inheritance. However, we have
Inheritance related knowledge:Private inheritance is not visible to derived classes (exist but not accessable)private and protect inheritance does not allow a base class pointer to point to a derived class (compilederror: ‘BaseClass‘ is an
1. Public inheritance indicates that the is-a relationship requires full inheritance of the interface, while private inheritance indicates that "the relationship based on something" requires only inheritance, and there are two rules for private
Note:1.private inheritance means is-implemented-in-terms-of (implemented according to something). It is usually lower than the compound (composition) level. But when derivated class needs to access the protected base classMember, or need to redefine
A(1) Private succession means "to achieve from something" . Only implementations are partially inherited. The interface part should be omitted;(2) It is only meaningful at the "implementation" level of the software, which is meaningless at the
Common inheritance (public) inheritance, private inheritance, and protection Inheritance (protected) are the three commonly used methods of inheritance.1. Public inheritancePublic inheritance is characterized by the public and protected members of
1. Public inheritance
Public inheritance is characterized by the public and protected members of the base class as members of derived classes, all of which remain in their original state, while private members of the base class remain private.
2.
ArticleDirectory
Wise and prudent use of private inheritance (use private inheritance judicious .)
Wise and prudent use of private inheritance (use private inheritance judicious .)
Two rules inherited by private:
1. the compiler will
Public and private inheritance (private), protected inheritance (protected) are three commonly used methods of inheritance. 1. Public inheritance Public inheritance is characterized by public members of the base class and protected members as
First, the article for the reasonSimple and clear reasons, commonplace but not really solve the problem, want to understand this problem.Ii. a lengthy definitionLet's take a look at these lengthy definitions:Public inheritance:
When a class
Public, private, and protected are common inheritance methods.
1. Public inheritance)
Public inheritance is characterized by the original state of both the public members of the base class and the protected members as the members of the derived
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.