<?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[Unterklassenproblem mit einer Map]]></title><description><![CDATA[<p>Hallo alle zusammen!</p>
<p>Ich hoffe Ihr könnt mir weiterhelfen:</p>
<p>Ich habe zwei Klassen, eine mit dem Namen &quot;Object&quot;, und eine Unterklasse von &quot;Object&quot; mit dem Namen &quot;String&quot;. Doch sobald ich eine Instanz von &quot;String&quot; erstelle und diese in einer Map speichere, gibt diese plötzlich nur noch das aus, was eigentlich die Oberklasse ausgeben sollte, hier ein gekürzter Beispiel-Code, was mache ich falsch? Ich hoffe Ihr könnt mir weiterhelfen, danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;map&gt;
using namespace std;

class Object {
	public:
		string getContent();
};

class String : public Object {
	public:
		string content;
		string getContent();
		void setContent(string content);
};

string Object::getContent(){ return &quot;&lt;object&gt;&quot;; }
string String::getContent(){ return this-&gt;content; }
void String::setContent(string content){ this-&gt;content = content; }

int main(){
	map&lt;string, Object&gt; objects;

	String testString;
	testString.setContent(&quot;Test-String&quot;);
	cout &lt;&lt; testString.getContent() &lt;&lt; endl; //Ausgabe: Test-String

	objects[&quot;test&quot;] = testString;
	cout &lt;&lt; objects[&quot;test&quot;].getContent() &lt;&lt; endl; //Ausgabe: &lt;object&gt;

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/234487/unterklassenproblem-mit-einer-map</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 11:41:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/234487.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Feb 2009 15:23:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unterklassenproblem mit einer Map on Wed, 18 Feb 2009 15:23:10 GMT]]></title><description><![CDATA[<p>Hallo alle zusammen!</p>
<p>Ich hoffe Ihr könnt mir weiterhelfen:</p>
<p>Ich habe zwei Klassen, eine mit dem Namen &quot;Object&quot;, und eine Unterklasse von &quot;Object&quot; mit dem Namen &quot;String&quot;. Doch sobald ich eine Instanz von &quot;String&quot; erstelle und diese in einer Map speichere, gibt diese plötzlich nur noch das aus, was eigentlich die Oberklasse ausgeben sollte, hier ein gekürzter Beispiel-Code, was mache ich falsch? Ich hoffe Ihr könnt mir weiterhelfen, danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;map&gt;
using namespace std;

class Object {
	public:
		string getContent();
};

class String : public Object {
	public:
		string content;
		string getContent();
		void setContent(string content);
};

string Object::getContent(){ return &quot;&lt;object&gt;&quot;; }
string String::getContent(){ return this-&gt;content; }
void String::setContent(string content){ this-&gt;content = content; }

int main(){
	map&lt;string, Object&gt; objects;

	String testString;
	testString.setContent(&quot;Test-String&quot;);
	cout &lt;&lt; testString.getContent() &lt;&lt; endl; //Ausgabe: Test-String

	objects[&quot;test&quot;] = testString;
	cout &lt;&lt; objects[&quot;test&quot;].getContent() &lt;&lt; endl; //Ausgabe: &lt;object&gt;

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1665835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1665835</guid><dc:creator><![CDATA[apl]]></dc:creator><pubDate>Wed, 18 Feb 2009 15:23:10 GMT</pubDate></item><item><title><![CDATA[Reply to Unterklassenproblem mit einer Map on Wed, 18 Feb 2009 15:31:03 GMT]]></title><description><![CDATA[<p><a href="http://tutorial.schornboeck.net/virtual.htm" rel="nofollow">http://tutorial.schornboeck.net/virtual.htm</a></p>
<p>Stichwort: Slicing</p>
<p>Du musst Zeiger in der Map speichern, siehe dazu boost::ptr_map</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1665843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1665843</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 18 Feb 2009 15:31:03 GMT</pubDate></item></channel></rss>