<?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[Methode in Kindklasse überschreiben]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgendes Interface, dass alle Klasse implementieren sollen,<br />
die man in eine Datei speichern kann.</p>
<pre><code class="language-cpp">class Storeable
{
public:
  virtual void saveBinary(FILE *stream) throw(MyException) = 0;
  virtual void loadBinary(FILE *stream) throw(MyException) = 0;
  virtual void saveBinary(const char* filename) throw(MyException)
  {
    FILE *fp = fopen(filename, &quot;wb&quot;);
    if( fp == NULL )
      throw MyException(strerror(errno));
    this-&gt;saveBinary(fp);  
    fclose(fp);
  }  
  virtual void loadBinary(const char *filename) throw(MyException)
  {
      FILE *fp = fopen(filename, &quot;rb&quot;);
      if( fp == NULL )
        throw MyException(strerror(errno));
      this-&gt;loadBinary(fp);  
      fclose(fp);
  }
};
</code></pre>
<p>Meine abgeleitete Klasse sieht so aus:</p>
<pre><code class="language-cpp">class Child : public Storeable
{
public:
  ...
  virtual void saveBinary(FILE *stream) throw(MyException){...}
  virtual void loadBinary(FILE *stream) throw(MyException){...}
};
</code></pre>
<p>wenn ich nun in der main Child::saveBinary(const *char) aufrufe bekommen ich einen Fehler.</p>
<pre><code class="language-cpp">void main(void){
  Child myChild;
  mychild.saveBinary(&quot;datei.bin&quot;);
}
</code></pre>
<blockquote>
<p>error: no matching function for call to 'Child::saveBinary(const char*&amp;)'</p>
</blockquote>
<p>woran kann das liegen? Es sollte doch die Methode der Elternklasse aufgerufen werden.</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/182772/methode-in-kindklasse-überschreiben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 00:22:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182772.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 29 May 2007 08:28:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Methode in Kindklasse überschreiben on Tue, 29 May 2007 08:28:41 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgendes Interface, dass alle Klasse implementieren sollen,<br />
die man in eine Datei speichern kann.</p>
<pre><code class="language-cpp">class Storeable
{
public:
  virtual void saveBinary(FILE *stream) throw(MyException) = 0;
  virtual void loadBinary(FILE *stream) throw(MyException) = 0;
  virtual void saveBinary(const char* filename) throw(MyException)
  {
    FILE *fp = fopen(filename, &quot;wb&quot;);
    if( fp == NULL )
      throw MyException(strerror(errno));
    this-&gt;saveBinary(fp);  
    fclose(fp);
  }  
  virtual void loadBinary(const char *filename) throw(MyException)
  {
      FILE *fp = fopen(filename, &quot;rb&quot;);
      if( fp == NULL )
        throw MyException(strerror(errno));
      this-&gt;loadBinary(fp);  
      fclose(fp);
  }
};
</code></pre>
<p>Meine abgeleitete Klasse sieht so aus:</p>
<pre><code class="language-cpp">class Child : public Storeable
{
public:
  ...
  virtual void saveBinary(FILE *stream) throw(MyException){...}
  virtual void loadBinary(FILE *stream) throw(MyException){...}
};
</code></pre>
<p>wenn ich nun in der main Child::saveBinary(const *char) aufrufe bekommen ich einen Fehler.</p>
<pre><code class="language-cpp">void main(void){
  Child myChild;
  mychild.saveBinary(&quot;datei.bin&quot;);
}
</code></pre>
<blockquote>
<p>error: no matching function for call to 'Child::saveBinary(const char*&amp;)'</p>
</blockquote>
<p>woran kann das liegen? Es sollte doch die Methode der Elternklasse aufgerufen werden.</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294244</guid><dc:creator><![CDATA[slurm]]></dc:creator><pubDate>Tue, 29 May 2007 08:28:41 GMT</pubDate></item><item><title><![CDATA[Reply to Methode in Kindklasse überschreiben on Tue, 29 May 2007 08:36:47 GMT]]></title><description><![CDATA[<p>Du überdeckst die Methode in deiner Klasse Child. Du kannst eine Weiterleitung einrichten oder dem Compiler per &quot;using xyz&quot; mitteilen das du die Orginalmethode weiterhin anbieten willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294250</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294250</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Tue, 29 May 2007 08:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Methode in Kindklasse überschreiben on Tue, 29 May 2007 09:38:05 GMT]]></title><description><![CDATA[<p>Danke für die schnelle Antwort. Aber wo muss das &quot;using ...&quot; hin und wie ist die sytax? Ich finde nämlich dazu nur Informationen im Bezug auf namespaces.</p>
<p>Die Weiterleitung hab ich nun so gemacht:</p>
<pre><code class="language-cpp">class Child : public Storeable
{
public:
  ...
  virtual void saveBinary(FILE *stream) throw(MyException){...}
  virtual void loadBinary(FILE *stream) throw(MyException){...}
  virtual void saveBinary(const char* filename) throw(MyException){
    Storeable::saveBinary(filename);
  }
  virtual void loadBinary(const char *filename) throw(MyException){
    Storeable::loadBinary(filename);
  }
};
</code></pre>
<p>Ist da so richtig? Diesen Weg finde ich jedoch ein wenig umständlich, da ich mehrer Klassen habe, die so aussehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294300</guid><dc:creator><![CDATA[slurm]]></dc:creator><pubDate>Tue, 29 May 2007 09:38:05 GMT</pubDate></item><item><title><![CDATA[Reply to Methode in Kindklasse überschreiben on Tue, 29 May 2007 09:41:33 GMT]]></title><description><![CDATA[<p>Ja so sieht die Weiterleitung aus. Per using funktioniert das folgendermasen:</p>
<pre><code class="language-cpp">class Child : public Storeable
{
public:
  ...
  virtual void saveBinary(FILE *stream) throw(MyException){...}
  virtual void loadBinary(FILE *stream) throw(MyException){...}

  using Storable::loadBinary;
  using Storable::saveBinary;
};
</code></pre>
<p>Der Weg ist nur umständlich weil du versuchst Methoden zu überdecken. Du übschreibst die Methoden ja nicht sondern erzeugst neue Methoden mit ganz anderen Parametern aber gleichen Namen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294302</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Tue, 29 May 2007 09:41:33 GMT</pubDate></item></channel></rss>