<?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[Anfängerproblem mit Typcasting und STL-Vector]]></title><description><![CDATA[<p>Sers,</p>
<p>Ich hab ein Convertierungsproblem.</p>
<p>Kurzer Auszug aus der Klassenhierarchie:</p>
<pre><code class="language-cpp">class TglForm: public TglObject{

  public:
    int addComponent(TglComponent component);
</code></pre>
<p>Ich benutze diesen Vector:</p>
<pre><code class="language-cpp">vector&lt;TglObject*&gt; FormTable;
</code></pre>
<p>Ich möchte nun den Inhalt des Vectors als TglForm interpretieren und die dortige Funktion aufrufen:</p>
<pre><code class="language-cpp">return ((TglForm)*FormTable[parentFormID])-&gt;addComponent(component);
</code></pre>
<p>Der Compiler meint dazu:</p>
<pre><code>error: no matching function for call to `TglForm::TglForm(TglObject&amp;)'
</code></pre>
<p>Öhm...Was hab ich falsch gemacht?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/119240/anfängerproblem-mit-typcasting-und-stl-vector</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 22:06:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/119240.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Aug 2005 22:08:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfängerproblem mit Typcasting und STL-Vector on Mon, 29 Aug 2005 22:08:57 GMT]]></title><description><![CDATA[<p>Sers,</p>
<p>Ich hab ein Convertierungsproblem.</p>
<p>Kurzer Auszug aus der Klassenhierarchie:</p>
<pre><code class="language-cpp">class TglForm: public TglObject{

  public:
    int addComponent(TglComponent component);
</code></pre>
<p>Ich benutze diesen Vector:</p>
<pre><code class="language-cpp">vector&lt;TglObject*&gt; FormTable;
</code></pre>
<p>Ich möchte nun den Inhalt des Vectors als TglForm interpretieren und die dortige Funktion aufrufen:</p>
<pre><code class="language-cpp">return ((TglForm)*FormTable[parentFormID])-&gt;addComponent(component);
</code></pre>
<p>Der Compiler meint dazu:</p>
<pre><code>error: no matching function for call to `TglForm::TglForm(TglObject&amp;)'
</code></pre>
<p>Öhm...Was hab ich falsch gemacht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/860999</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/860999</guid><dc:creator><![CDATA[KFlash]]></dc:creator><pubDate>Mon, 29 Aug 2005 22:08:57 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem mit Typcasting und STL-Vector on Mon, 29 Aug 2005 22:48:46 GMT]]></title><description><![CDATA[<p>statt</p>
<pre><code class="language-cpp">((TglForm)*FormTable[parentFormID])-&gt;addComponent(component);
</code></pre>
<pre><code class="language-cpp">static_cast&lt;TglForm*&gt;(FormTable[parentFormID])-&gt;addComponent(component);
</code></pre>
<p>Wobei ich nicht glaube, dass das dein Problem löst. Bist du dir sicher, dass ein &quot;TglObject&quot; ein &quot;TglForm&quot; <em>ist</em>? und nicht stattdessen &quot;TglForm&quot; mit Hilfe von &quot;TglObject&quot; implementiert werden sollte? ...</p>
<p>Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/861011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/861011</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Mon, 29 Aug 2005 22:48:46 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem mit Typcasting und STL-Vector on Tue, 30 Aug 2005 09:55:39 GMT]]></title><description><![CDATA[<p>Danke das war die Lösung.</p>
<p>Nein also...TglObject ist Vorfahre von TglForm. Die Form ist nur eine Spezialisierung. Das klappt schon so, oder funktioniert OOP in C++ anders... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/861235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/861235</guid><dc:creator><![CDATA[KFlash]]></dc:creator><pubDate>Tue, 30 Aug 2005 09:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem mit Typcasting und STL-Vector on Tue, 30 Aug 2005 11:34:40 GMT]]></title><description><![CDATA[<p>KFlash schrieb:</p>
<blockquote>
<p>Danke das war die Lösung.</p>
<p>Nein also...TglObject ist Vorfahre von TglForm. Die Form ist nur eine Spezialisierung. Das klappt schon so, oder funktioniert OOP in C++ anders... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>wenn im vector an der stelle aber kein TglForm Zeiger sondern ein anderer<br />
TglObject (TglCanvas oder weiss der Geier was) ist, dann bekommst du ein Problem...</p>
<p>IMHO deuten solche Casts häufig auf einen Designfehler hin.<br />
Überleg dir mal ob du wirklich ein vector&lt;TglObject*&gt; brauchst,<br />
oder ob nicht ein vector&lt;TglForm*&gt; angebrachter wäre.</p>
<p>phlox</p>
]]></description><link>https://www.c-plusplus.net/forum/post/861299</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/861299</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Tue, 30 Aug 2005 11:34:40 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem mit Typcasting und STL-Vector on Tue, 30 Aug 2005 12:19:36 GMT]]></title><description><![CDATA[<p>Auch eine Überlegung wert wäre</p>
<pre><code class="language-cpp">dynamic_cast&lt;TglForm&amp;&gt;(FormTable[parentFormID]).addComponent(...);
</code></pre>
<p>Das macht im Gegensatz zum static_cast Radautz, wenn es fehlschlägt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/861331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/861331</guid><dc:creator><![CDATA[operator void]]></dc:creator><pubDate>Tue, 30 Aug 2005 12:19:36 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem mit Typcasting und STL-Vector on Tue, 30 Aug 2005 23:43:35 GMT]]></title><description><![CDATA[<p>Ich habs jetzt so hingegrigt:</p>
<pre><code class="language-cpp">return ((TglForm*)FormTable[parentFormID])-&gt;addComponent(component);
</code></pre>
<p>Das mit dem Design stimmt...allerdings kann man doch abfragen, auf was der Pointer Zeigt oder? In Delphi konnte man das checken...</p>
<p>also:</p>
<pre><code>obj : TObject;

Zuweisung(Obj)

if Obj is TWasWeisIch then TuWas;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/861744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/861744</guid><dc:creator><![CDATA[KFlash]]></dc:creator><pubDate>Tue, 30 Aug 2005 23:43:35 GMT</pubDate></item></channel></rss>