<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem bei Vererbung]]></title><description><![CDATA[<p>Hallo</p>
<p>Also ich hab ein Problem mit der Erreichbarkeit meiner protected Variable.</p>
<p>Hier mal die Classen</p>
<pre><code class="language-cpp">class Shape {

protected:

	Color color;

public:

   	Shape();	//Konstruktor

   	virtual ~Shape();	//Destructor

	virtual void draw() const=0; 

	virtual void move(const Coord&amp;)=0;

	virtual double area()const = 0;

	virtual void write(ostream&amp; strm)const=0;	

	void setColor(const Color&amp; color=Black);

	void setType(figType);	

	figType getType() const;	

	void className()const;

private:

	figType type;

};

ostream&amp; operator&lt;&lt; (ostream&amp;, const Shape&amp;);

ostream&amp; operator&lt;&lt; (ostream&amp;, const Color&amp;);

istream&amp; operator&gt;&gt; (istream&amp;, Shape&amp;);
</code></pre>
<pre><code class="language-cpp">class Point:public Shape{
	public:
		//Standart Konstruktor	
	    Point(const Coord&amp; xy=Coord(100,100),const Color&amp; color=Color(0,0,0),POINTSTYLE style=CROSS);
		Point(const Point&amp;);
		//void read(istream&amp; strm=cin);
		void write(ostream&amp; strm=cout)const;
		virtual void draw() const;
		virtual void move(const Coord&amp; d);
		virtual double area()const;

	private:
		POINTSTYLE style; //Style
		Coord xy; 	//Position

};
ostream&amp; operator&lt;&lt; (ostream&amp;, const Point&amp;);
ostream&amp; operator&lt;&lt; (ostream&amp;, const Color&amp;);
</code></pre>
<p>Nun kommen die Funktionen die mir Probleme machen.</p>
<p>[cpp]void Point::write(ostream&amp; strm) const<br />
{<br />
strm &lt;&lt; &quot;Point: Pos.:&quot;&lt;&lt; xy &lt;&lt; &quot;Color:&quot; &lt;&lt; <strong>color</strong> &lt;&lt; &quot;Linestyle:&quot; &lt;&lt; style &lt;&lt;endl;<br />
}</p>
<p>ostream&amp; operator&lt;&lt; (ostream&amp; strm, const Point&amp; p)<br />
{<br />
p.write(strm);<br />
return strm;<br />
}[/cpp]</p>
<p>Wenn ich nun aber <strong>color</strong> entferne wird alles richtig compiliert. Aber ich brauch die Ausgabe von color.<br />
Warum ist color nicht erreichbar?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/147422/problem-bei-vererbung</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 07:36:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/147422.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 May 2006 17:24:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem bei Vererbung on Tue, 16 May 2006 17:24:03 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Also ich hab ein Problem mit der Erreichbarkeit meiner protected Variable.</p>
<p>Hier mal die Classen</p>
<pre><code class="language-cpp">class Shape {

protected:

	Color color;

public:

   	Shape();	//Konstruktor

   	virtual ~Shape();	//Destructor

	virtual void draw() const=0; 

	virtual void move(const Coord&amp;)=0;

	virtual double area()const = 0;

	virtual void write(ostream&amp; strm)const=0;	

	void setColor(const Color&amp; color=Black);

	void setType(figType);	

	figType getType() const;	

	void className()const;

private:

	figType type;

};

ostream&amp; operator&lt;&lt; (ostream&amp;, const Shape&amp;);

ostream&amp; operator&lt;&lt; (ostream&amp;, const Color&amp;);

istream&amp; operator&gt;&gt; (istream&amp;, Shape&amp;);
</code></pre>
<pre><code class="language-cpp">class Point:public Shape{
	public:
		//Standart Konstruktor	
	    Point(const Coord&amp; xy=Coord(100,100),const Color&amp; color=Color(0,0,0),POINTSTYLE style=CROSS);
		Point(const Point&amp;);
		//void read(istream&amp; strm=cin);
		void write(ostream&amp; strm=cout)const;
		virtual void draw() const;
		virtual void move(const Coord&amp; d);
		virtual double area()const;

	private:
		POINTSTYLE style; //Style
		Coord xy; 	//Position

};
ostream&amp; operator&lt;&lt; (ostream&amp;, const Point&amp;);
ostream&amp; operator&lt;&lt; (ostream&amp;, const Color&amp;);
</code></pre>
<p>Nun kommen die Funktionen die mir Probleme machen.</p>
<p>[cpp]void Point::write(ostream&amp; strm) const<br />
{<br />
strm &lt;&lt; &quot;Point: Pos.:&quot;&lt;&lt; xy &lt;&lt; &quot;Color:&quot; &lt;&lt; <strong>color</strong> &lt;&lt; &quot;Linestyle:&quot; &lt;&lt; style &lt;&lt;endl;<br />
}</p>
<p>ostream&amp; operator&lt;&lt; (ostream&amp; strm, const Point&amp; p)<br />
{<br />
p.write(strm);<br />
return strm;<br />
}[/cpp]</p>
<p>Wenn ich nun aber <strong>color</strong> entferne wird alles richtig compiliert. Aber ich brauch die Ausgabe von color.<br />
Warum ist color nicht erreichbar?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1059058</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059058</guid><dc:creator><![CDATA[Zed(gast)]]></dc:creator><pubDate>Tue, 16 May 2006 17:24:03 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Tue, 16 May 2006 17:38:31 GMT]]></title><description><![CDATA[<p>versuchs mal mit</p>
<pre><code>Shape::color
</code></pre>
<p>nur ne Idee <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>mfg maddin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1059069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059069</guid><dc:creator><![CDATA[kruemeltee]]></dc:creator><pubDate>Tue, 16 May 2006 17:38:31 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Tue, 16 May 2006 21:26:10 GMT]]></title><description><![CDATA[<p>Was für Compilefehler bekommst du denn?<br />
Eigentlich sollte es sich problemlos übersetzen lassen, auch _mit_ color.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1059178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059178</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 16 May 2006 21:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Wed, 17 May 2006 09:08:00 GMT]]></title><description><![CDATA[<p>Ne leider geht es nicht mit Shape::color</p>
<p>Die Fehlermeldug ist</p>
<blockquote>
<p>g++ SimpleOutputDemo.o Interface.o Shape.o Coord.o Line.o Point.o SimpleOutput.o -L/usr/qt/3/lib -L /usr/X11R6/lib -lXext -lX11 -lm -lqt -o Simple<br />
Point.o: In function <code>Point::write(std::basic\_ostream&lt;char, std::char\_traits&lt;char&gt; &gt;&amp;) const': Point.cpp:(.text+0x2d9): undefined reference to</code>operator&lt;&lt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, Color const&amp;)'<br />
collect2: ld returned 1 exit status<br />
make: *** [Simple] Error 1</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1059361</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059361</guid><dc:creator><![CDATA[Zed(gast)]]></dc:creator><pubDate>Wed, 17 May 2006 09:08:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Wed, 17 May 2006 09:11:00 GMT]]></title><description><![CDATA[<p>Das ist ein Linkerfehler. Hast du denn den hier</p>
<pre><code class="language-cpp">ostream&amp; operator&lt;&lt; (ostream&amp;, const Color&amp;);
</code></pre>
<p>überhaupt irgendwo definiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1059364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059364</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 17 May 2006 09:11:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Wed, 17 May 2006 09:27:24 GMT]]></title><description><![CDATA[<p>Das Problem ha sich erledigt</p>
<pre><code class="language-cpp">class Color

   {

   public:

      // administration functions

      Color(const uchar r, const uchar g, const uchar b) 

          : red(r), green(g), blue(b) { }

      Color() { red = green = blue = 0; }

      // access

      uchar getRed   (void) const            { return red;   }

      uchar getBlue  (void) const            { return blue;  }

      uchar getGreen (void) const            { return green; }

      int operator==(const Color&amp; c) const { return (red == c.red) &amp;&amp; 

                                                      (blue == c.blue) &amp;&amp; 

                                                      (green == c.green); }

      int operator!=(const Color&amp; c) const { return !(*this == c); }

      // implementation

      void  setColor (const uchar r, const uchar g, const uchar b) 

                           { red = r; green = g; blue = b; }

      void setRed   (uchar const r)             { red = r;      }

      void setBlue  (uchar const b)             { blue = b;     }

      void setGreen (uchar const g)             { green = g;    }

   private:

      uchar red, green, blue;	// Color attributes

   }; // class Color
</code></pre>
<p>Die Class color hat keinen operator &lt;&lt; darum hat die augabe nicht funktioniert.<br />
Hab nun so gelöst</p>
<pre><code class="language-cpp">void Point::write(ostream&amp; strm) const
{
   strm &lt;&lt; &quot;Point: Pos.:&quot;&lt;&lt; xy &lt;&lt; &quot;Color:&quot; &lt;&lt; (int)(color.getBlue()) &lt;&lt; (int)(color.getRed())&lt;&lt;(int)(color.getGreen()) &lt;&lt;&quot;Linestyle:&quot; &lt;&lt;  style &lt;&lt;endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1059376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059376</guid><dc:creator><![CDATA[Zed(gast)]]></dc:creator><pubDate>Wed, 17 May 2006 09:27:24 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Wed, 17 May 2006 09:34:38 GMT]]></title><description><![CDATA[<p>Zed(gast) schrieb:</p>
<blockquote>
<p>Die Class color hat keinen operator &lt;&lt; darum hat die augabe nicht funktioniert.<br />
Hab nun so gelöst</p>
</blockquote>
<p>Warum spendierst du ihr dann keinen Operator &lt;&lt; ? Deklariert hast du ihn ja schon:</p>
<pre><code class="language-cpp">ostream&amp; operator&lt;&lt;(ostream&amp; strm,const Color&amp; c)
{
  strm&lt;&lt;(int)c.getBlue()&lt;&lt;' '&lt;&lt;(int)c.getRed()&lt;&lt;' '&lt;&lt;(int)c.getGreen();
  return strm;
}
</code></pre>
<p>(btw, das 'const' bei den Parametern benötigst du nur, wenn du mit Referenzen oder Pointern arbeitest - bei Wertübergabe ist es unnötig)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1059383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059383</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 17 May 2006 09:34:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Vererbung on Wed, 17 May 2006 15:58:47 GMT]]></title><description><![CDATA[<p>Da kann ich leider nicht so frei Arbeiten.<br />
Da nimmt es unser Prof ziemlich genau.</p>
<p>Nach dem Moto was er sagt ist Gesetz</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1059676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1059676</guid><dc:creator><![CDATA[Zed(gast)]]></dc:creator><pubDate>Wed, 17 May 2006 15:58:47 GMT</pubDate></item></channel></rss>