<?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[Vererbung von Einzelnen Methoden?]]></title><description><![CDATA[<p>Huka, ich wollte Fragen, ob es prinziepiell möglich ist, nur einzelne Methoden von anderen Klassen zu Vererben. Ich wollte eigentlich nur die Methode &quot;what()&quot; der Klasse &quot;std::exception&quot; vererben.<br />
Hier soweit der Code:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include &lt;conio.h&gt;

class eCnull_division : public std::exception
{
}; 
// Klasse für das Ausnahmeobjekt, dass bei Division durch 0 geworfen wird
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/169616/vererbung-von-einzelnen-methoden</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 20:32:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/169616.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Jan 2007 00:22:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 00:22:55 GMT]]></title><description><![CDATA[<p>Huka, ich wollte Fragen, ob es prinziepiell möglich ist, nur einzelne Methoden von anderen Klassen zu Vererben. Ich wollte eigentlich nur die Methode &quot;what()&quot; der Klasse &quot;std::exception&quot; vererben.<br />
Hier soweit der Code:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include &lt;conio.h&gt;

class eCnull_division : public std::exception
{
}; 
// Klasse für das Ausnahmeobjekt, dass bei Division durch 0 geworfen wird
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1204747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1204747</guid><dc:creator><![CDATA[Shilka]]></dc:creator><pubDate>Sun, 07 Jan 2007 00:22:55 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 02:25:57 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>wenn ich dich richtig verstehe möchtest du eine Klasse von einer anderen Superklasse ableiten, aber nur eine Methode (in diesem Fall what()) nach außen sichtbar geben?</p>
<p>Du kannst die Vererbung als private kennzeichnen und die Methode what() explizit als public implementieren.</p>
<p>Grüße<br />
Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1204771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1204771</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 07 Jan 2007 02:25:57 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 14:01:11 GMT]]></title><description><![CDATA[<p>Wenn du nicht die gesamte Klasse erben willst, ist Vererbung ein Designfehler.</p>
<p>Was hindert dich daran, die Methode what() selbst zu definieren und std::exception::what() darin aufzurufen bzw. die komplette Klasse std::exception zu erben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1204980</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1204980</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Sun, 07 Jan 2007 14:01:11 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 14:56:10 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Wenn du nicht die gesamte Klasse erben willst, ist Vererbung ein Designfehler.</p>
<p>Was hindert dich daran, die Methode what() selbst zu definieren und std::exception::what() darin aufzurufen bzw. die komplette Klasse std::exception zu erben?</p>
</blockquote>
<p>Genau das meinte ich, wie bringe ich &quot;mein&quot; what dazu die andere Methode aufzurufen? Kannst du das kurz in nen Syntax Beispiel aufzeigen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205026</guid><dc:creator><![CDATA[Shilka]]></dc:creator><pubDate>Sun, 07 Jan 2007 14:56:10 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 15:04:12 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class eCnull_division
{
public:
    const char * const what()
    {
        return std::exception().what();
    }
};
</code></pre>
<p>^^</p>
<p>Erklär mir mal bitte, warum eCnull_division nicht von std::exception erben soll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205035</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Sun, 07 Jan 2007 15:04:12 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 15:18:55 GMT]]></title><description><![CDATA[<p>weil ich nur What von der Klasse brauche und sonst nichts?;)</p>
<p>Dachte es wäre vllt Leistungssparender nur bestimmte Teile einer Klasse abzuleiten anstatt alles.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205046</guid><dc:creator><![CDATA[Shilka]]></dc:creator><pubDate>Sun, 07 Jan 2007 15:18:55 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 15:23:09 GMT]]></title><description><![CDATA[<p>Nein, das ist ein irrglaube. Sobald du erbst, hast du eine vtable. &quot;Wenig&quot; vererben gibt es technisch nicht. Außerdem sollte man meistens Design vor Technik stellen. Wenn deine eCnull_division eine exception ist, solltest du davon erben - basta. Sonst kannste OO gleich vergessen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205052</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Sun, 07 Jan 2007 15:23:09 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Sun, 07 Jan 2007 15:29:14 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<p>Sobald du erbst, hast du eine vtable.</p>
</blockquote>
<p>Echt? Ich behaupte das ist nicht so.</p>
<p>Btw gibts nichts sonst zu erben, die g++-lib sieht so aus:</p>
<pre><code class="language-cpp">namespace std
{
  /**
   *  @brief Base class for all library exceptions.
   *
   *  This is the base class for all exceptions thrown by the standard
   *  library, and by certain language expressions.  You are free to derive
   *  your own %exception classes, or use a different hierarchy, or to
   *  throw non-class data (e.g., fundamental types).
   */
  class exception
  {
  public:
    exception() throw() { }
    virtual ~exception() throw();
    /** Returns a C-style character string describing the general cause
     *  of the current error.  */
    virtual const char* what() const throw();
  };
...
</code></pre>
<p>Was die MS Implementierung fuern Schrott da reinpackt kann ich dir nicht sagen. Ist mir irgendwie unverstaendlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205055</guid><dc:creator><![CDATA[Entenwickler]]></dc:creator><pubDate>Sun, 07 Jan 2007 15:29:14 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Mon, 08 Jan 2007 08:07:10 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/14887">@Shilka</a>: Was für eine Beziehung soll denn zwischen deiner Klasse und std::exception bestehen? Wenn das da oben eine Exception sein soll, ist Vererbung (und zwar der kompletten Klasse) der richtige Weg. Wenn deine Klasse &quot;nur&quot; eine Methode namens what() benötigt, kannst du sie auch selber schreiben.</p>
<p>Artchi schrieb:</p>
<blockquote>
<p>Sobald du erbst, hast du eine vtable.</p>
</blockquote>
<p>das ist imho falsch - eine vtable bekommst du nur, wenn du virtuelle Funktionen verwenden willst (oder von einer Klasse erbst, die virtuelle Funktionen verwendet).<br />
(und soviel Platz benötigt die vtable nun auch wieder nicht)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205410</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205410</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 08 Jan 2007 08:07:10 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Mon, 08 Jan 2007 08:18:24 GMT]]></title><description><![CDATA[<p>Und Vererbung ohne virtuelle Methode ist richtig? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205417</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205417</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Mon, 08 Jan 2007 08:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Mon, 08 Jan 2007 08:26:44 GMT]]></title><description><![CDATA[<p>technisch gesehen ja (d.h. du darfst von jeder Klasse ableiten - du mußt nur wissen, ob es Sinn macht).</p>
<p>(z.B. gibt's in der MFC einige Wrapper-Klassen, die von WinAPI (C-)Structs abgeleitet sind)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205428</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 08 Jan 2007 08:26:44 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung von Einzelnen Methoden? on Mon, 08 Jan 2007 20:25:50 GMT]]></title><description><![CDATA[<p>Zum Thema vtables: <a href="http://www.codeproject.com/cpp/FastDelegate.asp" rel="nofollow">http://www.codeproject.com/cpp/FastDelegate.asp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1206012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1206012</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 08 Jan 2007 20:25:50 GMT</pubDate></item></channel></rss>