Re: Friend functions not inherited
This is a multi-part message in MIME format.
----------------6595172031321713237
Content-Type: text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
On 2010-11-04 06:37:47 -0400, Andrea Crotti said:
To my surprise I read that some time ago, so what I thought it could
work in fact it could not work.
If the title is an exact quote, you were misinformed. The actual rule
is that *friendship* is not inherited.
class Extended : Base
Now Extended has a *private* base named Base. Change it to
class Extended : public Base
and everything should work just fine. There's no problem calling
operator<<(ostream&, const Base&) with an object of type Extended.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
----------------6595172031321713237
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.32">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 15.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 15.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 14.0px; font: 12.0px Helvetica; color: #14118f}
p.p4 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 14.0px; font: 12.0px Helvetica; color: #14118f; min-height: 14.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #929292; min-height: 14.0px}
p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #929292}
</style>
</head>
<body>
<p class="p1">On 2010-11-04 06:37:47 -0400, Andrea Crotti said:</p>
<p class="p2"><br></p>
<p class="p3">To my surprise I read that some time ago, so what I thought it could</p>
<p class="p3">work in fact it could not work.</p>
<p class="p4"><br></p>
<p class="p5"><br></p>
<p class="p6">If the title is an exact quote, you were misinformed. The actual rule is that *friendship* is not inherited.</p>
<p class="p5"><br></p>
<p class="p3">class Extended : Base</p>
<p class="p7"><br></p>
<p class="p8">Now Extended has a *private* base named Base. Change it to</p>
<p class="p7"><br></p>
<p class="p8">class Extended : public Base</p>
<p class="p7"><br></p>
<p class="p8">and everything should work just fine. There's no problem calling operator<<(ostream&, const Base&) with an object of type Extended.</p>
<p class="p9"><br></p>
<p class="p10">--<span class="Apple-converted-space">?</span></p>
<p class="p10"><span class="Apple-converted-space">? </span>Pete</p>
<p class="p10">Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book)</p>
</body>
</html>
----------------6595172031321713237--