<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 11.6 &#8212; Adding, changing, and hiding members in a derived class</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: rahul nagar</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-96819</link>
		<dc:creator>rahul nagar</dc:creator>
		<pubDate>Wed, 11 Jan 2012 15:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-96819</guid>
		<description>Hi Alex,

First of all I would like to thank u on the wonderful tutorials ..It really helped me... Just a small Doubt in this part 

Base::PrintValue;

Here in above you have tried to change the access specifier to public by defining it into the public section of the derived class. However I tried the same and its giving me error .



class Base
{
   public:
   int m_a;
   Base(int a=0): m_a(a)
   {
     cout&lt;&lt;&quot;\n I am in base constructor \t&quot;&lt;&lt;m_a&lt;&lt;endl;
   }
   protected:
   void identify()
   {
     cout&lt;&lt;&quot;\n I am in base class \t&quot;&lt;&lt;m_a&lt;&lt;endl;
   }
};

class Derived :public Base
{
  public:
  int m_b;
  Derived(int a=0,int b=0):Base(a),m_b(b)
  {
     cout&lt;&lt;&quot;\n I am in Derived constructor \t&quot;&lt;&lt;m_b&lt;&lt;endl;
  }
  Base::identify;
};
int main()
{
  Derived d_obj(7,9);
  d_obj.identify();
  return 0;
}


Below are the errors ::

Error 433: &quot;inheritance.cpp&quot;, line 26 # The class name in an access declaration must be a base class.
      Derived::identify;
      ^^^^^^^^^^^^^^^^^^
Error 182: &quot;inheritance.cpp&quot;, line 36 # &quot;int main()&quot; cannot access protected member &quot;void Base::identify()&quot;.
      d_obj.identify();
      ^^^^^^^^^^^^^^^^

Please suggest on the same.</description>
		<content:encoded><![CDATA[<p>Hi Alex,</p>
<p>First of all I would like to thank u on the wonderful tutorials ..It really helped me&#8230; Just a small Doubt in this part </p>
<p>Base::PrintValue;</p>
<p>Here in above you have tried to change the access specifier to public by defining it into the public section of the derived class. However I tried the same and its giving me error .</p>
<p>class Base<br />
{<br />
   public:<br />
   int m_a;<br />
   Base(int a=0): m_a(a)<br />
   {<br />
     cout&lt;&lt;&quot;\n I am in base constructor \t&quot;&lt;&lt;m_a&lt;&lt;endl;<br />
   }<br />
   protected:<br />
   void identify()<br />
   {<br />
     cout&lt;&lt;&quot;\n I am in base class \t&quot;&lt;&lt;m_a&lt;&lt;endl;<br />
   }<br />
};</p>
<p>class Derived :public Base<br />
{<br />
  public:<br />
  int m_b;<br />
  Derived(int a=0,int b=0):Base(a),m_b(b)<br />
  {<br />
     cout&lt;&lt;&quot;\n I am in Derived constructor \t&quot;&lt;&lt;m_b&lt;&lt;endl;<br />
  }<br />
  Base::identify;<br />
};<br />
int main()<br />
{<br />
  Derived d_obj(7,9);<br />
  d_obj.identify();<br />
  return 0;<br />
}</p>
<p>Below are the errors ::</p>
<p>Error 433: &quot;inheritance.cpp&quot;, line 26 # The class name in an access declaration must be a base class.<br />
      Derived::identify;<br />
      ^^^^^^^^^^^^^^^^^^<br />
Error 182: &quot;inheritance.cpp&quot;, line 36 # &quot;int main()&quot; cannot access protected member &quot;void Base::identify()&quot;.<br />
      d_obj.identify();<br />
      ^^^^^^^^^^^^^^^^</p>
<p>Please suggest on the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: duetosideeffects</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-92640</link>
		<dc:creator>duetosideeffects</dc:creator>
		<pubDate>Sat, 25 Sep 2010 02:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-92640</guid>
		<description>Like my first question, I found the answer simply by continuing the tutorials... :D So to anyone who read my question and wondered themselves how to do that, I think the answer is in lesson 12.1
-(that&#039;s where I got it, but it&#039;s &quot;I think&quot; since I don&#039;t know if it&#039;s the most efficient/best way to do it)

Inside the child class&#039;s overloaded &lt;&lt; operator, I created a reference variable NPC equal to the child class, then just simply outputted it.

NPC operator&lt;&lt;
&lt;pre&gt;
ostream&amp; operator&lt;&lt; (ostream &amp;out, const NPC &amp;cNPCTemp)
{
	out &lt;&lt; ... &lt;&lt; ... &lt;&lt; ... &lt;&lt; ...
		// code that outputs stuff
	return out;
}
&lt;!--formatted--&gt;&lt;/pre&gt;

Drone operator&lt;&lt;
&lt;pre&gt;
ostream&amp; operator&lt;&lt; (ostream&amp; out, Drone &amp;cDrone)
{
	NPC &amp;rNPC = cDrone;	//cuz of Hungarian I didn&#039;t have to think about the names
	out &lt;&lt; rNPC;

	out &lt;&lt; ... &lt;&lt; ... &lt;&lt; ... &lt;&lt; ...
		// code that outputs the Drone specific stuff
	return out;
}
&lt;!--formatted--&gt;&lt;/pre&gt;

I am, however, running into an issue where if I try this with multiple inheritance, it calls the base (NPC) overloaded function more than once; I do have the classes in between virtual (chain is actually -- NPC -&gt;(Drone,  Special) -&gt; Enemy) 
Problem occurs when I call (cout &lt;&lt; cEnemy) overloaded function.

Is it possible, or is this one of the problems Multiple inheritance has?</description>
		<content:encoded><![CDATA[<p>Like my first question, I found the answer simply by continuing the tutorials&#8230; :D So to anyone who read my question and wondered themselves how to do that, I think the answer is in lesson 12.1<br />
-(that&#8217;s where I got it, but it&#8217;s &#8220;I think&#8221; since I don&#8217;t know if it&#8217;s the most efficient/best way to do it)</p>
<p>Inside the child class&#8217;s overloaded &lt;&lt; operator, I created a reference variable NPC equal to the child class, then just simply outputted it.</p>
<p>NPC operator&lt;&lt;</p>
<pre>
ostream&amp; operator&lt;&lt; (ostream &amp;out, const NPC &amp;cNPCTemp)
{
	out &lt;&lt; ... &lt;&lt; ... &lt;&lt; ... &lt;&lt; ...
		// code that outputs stuff
	return out;
}
<!--formatted--></pre>
<p>Drone operator&lt;&lt;</p>
<pre>
ostream&amp; operator&lt;&lt; (ostream&amp; out, Drone &amp;cDrone)
{
	NPC &amp;rNPC = cDrone;	//cuz of Hungarian I didn&#39;t have to think about the names
	out &lt;&lt; rNPC;

	out &lt;&lt; ... &lt;&lt; ... &lt;&lt; ... &lt;&lt; ...
		// code that outputs the Drone specific stuff
	return out;
}
<!--formatted--></pre>
<p>I am, however, running into an issue where if I try this with multiple inheritance, it calls the base (NPC) overloaded function more than once; I do have the classes in between virtual (chain is actually &#8212; NPC -&gt;(Drone,  Special) -&gt; Enemy)<br />
Problem occurs when I call (cout &lt;&lt; cEnemy) overloaded function.</p>
<p>Is it possible, or is this one of the problems Multiple inheritance has?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: duetosideeffects</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-92570</link>
		<dc:creator>duetosideeffects</dc:creator>
		<pubDate>Fri, 24 Sep 2010 01:09:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-92570</guid>
		<description>I have a real question that I was hoping would&#039;ve been asked in the comments, not just people picking at tiny errors in the tutorial...

I have an inheritance chain
NPC -&gt; Drone
I have overloaded the &lt;&lt; operator, as a friend function, to output its info in the NPC (parent) class, then I created the Drone (child) class. When I make something like this
&lt;pre&gt;
Drone cDr01; cout &lt;&lt; cDr01;
&lt;/pre&gt;
Of course, it outputs all of the info kept in NPC as previously created, and nothing from Drone.
If I re-overload the &lt;&lt; operator in Drone, it overrides the NPC version. I also don&#039;t want to have to duplicate code, as in copy all of the previous code to the new one with the extra functionality, especially if I possibly wouldn&#039;t have access to it. I tried doing what was instructed above, to add the function call to the base in the derived version, but since it&#039;s an I/O operator, I can&#039;t seem to make it work.

Basically, How do you add functionality to an overloaded &lt;&lt; operator declared as a friend function.</description>
		<content:encoded><![CDATA[<p>I have a real question that I was hoping would&#8217;ve been asked in the comments, not just people picking at tiny errors in the tutorial&#8230;</p>
<p>I have an inheritance chain<br />
NPC -&gt; Drone<br />
I have overloaded the &lt;&lt; operator, as a friend function, to output its info in the NPC (parent) class, then I created the Drone (child) class. When I make something like this</p>
<pre>
Drone cDr01; cout &lt;&lt; cDr01;
</pre>
<p>Of course, it outputs all of the info kept in NPC as previously created, and nothing from Drone.<br />
If I re-overload the &lt;&lt; operator in Drone, it overrides the NPC version. I also don&#039;t want to have to duplicate code, as in copy all of the previous code to the new one with the extra functionality, especially if I possibly wouldn&#039;t have access to it. I tried doing what was instructed above, to add the function call to the base in the derived version, but since it&#039;s an I/O operator, I can&#039;t seem to make it work.</p>
<p>Basically, How do you add functionality to an overloaded &lt;&lt; operator declared as a friend function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C++ Tutorial and Online Ebook</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-87415</link>
		<dc:creator>C++ Tutorial and Online Ebook</dc:creator>
		<pubDate>Wed, 30 Jun 2010 01:00:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-87415</guid>
		<description>[...] 11.6 Adding, changing, and hiding members in a derived class [...]</description>
		<content:encoded><![CDATA[<p>[...] 11.6 Adding, changing, and hiding members in a derived class [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tylerfb11</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-84462</link>
		<dc:creator>tylerfb11</dc:creator>
		<pubDate>Tue, 11 May 2010 20:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-84462</guid>
		<description>Which occurance are you refering to?
BTW, I&#039;m terible with grammar and such in Engilsh (my first language) but I can still code in C++. I just don&#039;t really care a whole lot about proper &#039;santax&#039; in everyday language becuase, with a little bit of common scence, anyone can esaliy figure out what you&#039;re trying to say.

-Tyler</description>
		<content:encoded><![CDATA[<p>Which occurance are you refering to?<br />
BTW, I&#8217;m terible with grammar and such in Engilsh (my first language) but I can still code in C++. I just don&#8217;t really care a whole lot about proper &#8216;santax&#8217; in everyday language becuase, with a little bit of common scence, anyone can esaliy figure out what you&#8217;re trying to say.</p>
<p>-Tyler</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pintsize</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-84452</link>
		<dc:creator>Pintsize</dc:creator>
		<pubDate>Tue, 11 May 2010 13:13:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-84452</guid>
		<description>typo:

It’s also common [b]to[/b] for developers to release header files containing class definitions

Thanks again for this absolutely wonderful tutorials!</description>
		<content:encoded><![CDATA[<p>typo:</p>
<p>It’s also common [b]to[/b] for developers to release header files containing class definitions</p>
<p>Thanks again for this absolutely wonderful tutorials!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-79191</link>
		<dc:creator>Fred</dc:creator>
		<pubDate>Sat, 27 Feb 2010 02:52:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-79191</guid>
		<description>Please learn to spell &quot;its&quot; without an apostrophe. I cannot understand how someone could purport to understand the arcane syntax of C++, yet remain indifferent to the straightforward English syntax of apostrophes.</description>
		<content:encoded><![CDATA[<p>Please learn to spell &#8220;its&#8221; without an apostrophe. I cannot understand how someone could purport to understand the arcane syntax of C++, yet remain indifferent to the straightforward English syntax of apostrophes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pablo</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-76634</link>
		<dc:creator>Pablo</dc:creator>
		<pubDate>Sun, 17 Jan 2010 04:05:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-76634</guid>
		<description>In the paragraph you start with &quot;A word of warning...&quot; It&#039;s said that the type of the  returned value by the function in the Base class must be the same type in the Derived class in order the compiler to not to issue an error, well, I&#039;ve tried changing it and I&#039;ve got no error, may it be dependent of the compiler used? or may be it is an overloaded function or a new definition of it in the Derived class!</description>
		<content:encoded><![CDATA[<p>In the paragraph you start with &#8220;A word of warning&#8230;&#8221; It&#8217;s said that the type of the  returned value by the function in the Base class must be the same type in the Derived class in order the compiler to not to issue an error, well, I&#8217;ve tried changing it and I&#8217;ve got no error, may it be dependent of the compiler used? or may be it is an overloaded function or a new definition of it in the Derived class!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-69750</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Sun, 04 Oct 2009 09:12:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-69750</guid>
		<description>in line 736: &lt;pre&gt; When a member function is called with a derived class object, the the compiler...&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>in line 736:
<pre> When a member function is called with a derived class object, the the compiler...</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Supreame</title>
		<link>http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/comment-page-1/#comment-62548</link>
		<dc:creator>Supreame</dc:creator>
		<pubDate>Wed, 17 Jun 2009 08:13:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/116-adding-changing-and-hiding-members-in-a-derived-class/#comment-62548</guid>
		<description>&lt;cite&gt; If the return value does not match, the compiler will issue an error. &lt;/cite&gt;
The return value of the Identify() function in the Derived class dosen&#039;t have to be identical with the return value of Identify() from Base class . I tested it with VC Express 2008 compiler:
&lt;pre&gt;
     int Identify() { cout &lt;&lt; &quot;I am a Derived&quot; &lt;&lt; endl; return 0;}
&lt;!--formatted--&gt;&lt;/pre&gt;
and it compiles ok.

Another thing, after cDerived.Identify() you forgot a &quot;;&quot; in this code part
&lt;pre&gt;
int main()
{
    Base cBase(5);
    cBase.Identify();

    Derived cDerived(7);
    cDerived.Identify()

    return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><cite> If the return value does not match, the compiler will issue an error. </cite><br />
The return value of the Identify() function in the Derived class dosen&#8217;t have to be identical with the return value of Identify() from Base class . I tested it with VC Express 2008 compiler:</p>
<pre>
     int Identify() { cout &lt;&lt; &quot;I am a Derived&quot; &lt;&lt; endl; return 0;}
<!--formatted--></pre>
<p>and it compiles ok.</p>
<p>Another thing, after cDerived.Identify() you forgot a &#8220;;&#8221; in this code part</p>
<pre>
int main()
{
    Base cBase(5);
    cBase.Identify();

    Derived cDerived(7);
    cDerived.Identify()

    return 0;
}
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

