Difference between private, public, and protected inheritance?
What is the difference between `public`, `private`, and `protected` inheritance in C++? All of the questions I've found on SO deal with specific cases.
Patrick B.
answered 10/06/19
Math and computer tutor/teacher
Access
public
protected
private
Same class
yes
yes
yes
Derived classes
yes
yes
no
Outside classes
yes
no
no
A derived class inherits all base class methods with the following exceptions −
Constructors, destructors and copy constructors of the base class.
Overloaded operators of the base class.
The friend functions of the base class.
Still looking for help? Get the right answer, fast.
OR
Find an Online Tutor Now
Choose an expert and meet online.
No packages or subscriptions, pay only for the time you need.
¢
€
£
¥
‰
µ
·
•
§
¶
ß
‹
›
«
»
<
>
≤
≥
–
—
¯
‾
¤
¦
¨
¡
¿
ˆ
˜
°
−
±
÷
⁄
×
ƒ
∫
∑
∞
√
∼
≅
≈
≠
≡
∈
∉
∋
∏
∧
∨
¬
∩
∪
∂
∀
∃
∅
∇
∗
∝
∠
´
¸
ª
º
†
‡
À
Á
Â
Ã
Ä
Å
Æ
Ç
È
É
Ê
Ë
Ì
Í
Î
Ï
Ð
Ñ
Ò
Ó
Ô
Õ
Ö
Ø
Œ
Š
Ù
Ú
Û
Ü
Ý
Ÿ
Þ
à
á
â
ã
ä
å
æ
ç
è
é
ê
ë
ì
í
î
ï
ð
ñ
ò
ó
ô
õ
ö
ø
œ
š
ù
ú
û
ü
ý
þ
ÿ
Α
Β
Γ
Δ
Ε
Ζ
Η
Θ
Ι
Κ
Λ
Μ
Ν
Ξ
Ο
Π
Ρ
Σ
Τ
Υ
Φ
Χ
Ψ
Ω
α
β
γ
δ
ε
ζ
η
θ
ι
κ
λ
μ
ν
ξ
ο
π
ρ
ς
σ
τ
υ
φ
χ
ψ
ω
ℵ
ϖ
ℜ
ϒ
℘
ℑ
←
↑
→
↓
↔
↵
⇐
⇑
⇒
⇓
⇔
∴
⊂
⊃
⊄
⊆
⊇
⊕
⊗
⊥
⋅
⌈
⌉
⌊
⌋
〈
〉
◊