<?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[Mehrere Objekte einer selbsterstellten Klasse erzeugen]]></title><description><![CDATA[<p>Hallo liebe Community,</p>
<p>Ich bin absoluter C++ Neuling und würde gerne mehrere Objekte der Klasse &quot;FullMatrix&quot; erstellen, die jemand anderer geschrieben und mir zur Verfügung gestellt hat (siehe unten). Seltsamerweise funktioniert die Erstellung EINES Objektes problemlos, d.h. folgendes Codebeispiel wird ohne Fehler kompiliert:</p>
<pre><code>#include &quot;MatrixReal.hh&quot;

int main (int argc, char **argv) {
   int m = 4;
   int n = 3;
   FullMatrix matrix1(m,n);
   return 0;
}
</code></pre>
<p>Sobald ich jedoch zwei oder mehrere Objekte erzeugen will...</p>
<pre><code>#include &quot;MatrixReal.hh&quot;

int main (int argc, char **argv) {
   int m = 4;
   int n = 3;
   FullMatrix matrix1(m,n);
   FullMatrix matrix2(m,n);
   return 0;
}
</code></pre>
<p>...bekomme ich vom Compiler (g++) die folgende Fehlermeldung:</p>
<blockquote>
<p>/tmp/ccj3K052.o: In function <code>FullMatrix::~FullMatrix()': test.c:(.text.\_ZN10FullMatrixD2Ev\[\_ZN10FullMatrixD5Ev\]+0x7): undefined reference to</code>vtable for FullMatrix'<br />
/tmp/ccj3K052.o: In function <code>FullMatrix::~FullMatrix()': test.c:(.text.\_ZN10FullMatrixD0Ev\[\_ZN10FullMatrixD5Ev\]+0x7): undefined reference to</code>vtable for FullMatrix'<br />
/tmp/ccj3K052.o: In function <code>main': test.c:(.text.startup+0x1e): undefined reference to</code>vtable for FullMatrix'<br />
test.c:(.text.startup+0x46): undefined reference to `vtable for FullMatrix'<br />
collect2: ld returned 1 exit status<br />
make: *** [TestProg] Error 1</p>
</blockquote>
<p>Kann mir bitte jemand sagen, was genau ich falsch mache?</p>
<pre><code>#ifndef MATRIX_REAL_HH
#define MATRIX_REAL_HH

#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;ArrayReal.hh&gt;

class MatrixReal {
  public:

    const int m, n;

    MatrixReal(int lns, int cls) : m(lns), n(cls) {}

    MatrixReal(int lc) : m(lc), n(lc) {}

    virtual void            multiply_addto(const ArrayReal &amp;vec,
                                                 ArrayReal &amp;result) const = 0;

    void multiply(const ArrayReal &amp;vec, ArrayReal &amp;result) const {
      result = ZeroVector();
      multiply_addto(vec, result);
    }

    virtual ~MatrixReal(){}
};

/*******************************************************************************

*******************************************************************************/
class FullMatrix : public MatrixReal {
  public:

    Real * const ptr;

    FullMatrix(int m, int n) : MatrixReal(m, n), ptr(new Real[m * n]) {}
    FullMatrix(int m) : MatrixReal(m), ptr(new Real[m * m]) {}
    FullMatrix(const FullMatrix &amp;src);
    void operator = (const FullMatrix &amp;src);
    virtual ~FullMatrix() { delete [] ptr; }

    Real &amp; operator () (int i, int j) { return ptr[n * i + j]; }

    Real operator () (int i, int j) const { return ptr[n * i + j]; }

    void multiply_addto(const ArrayReal &amp;vec,
                              ArrayReal &amp;result) const;

    void invert();
    void invert_and_store(FullMatrix &amp;inv);
};

#endif // MATRIX_REAL_HH
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/321034/mehrere-objekte-einer-selbsterstellten-klasse-erzeugen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 13:14:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321034.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 21 Oct 2013 14:31:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mehrere Objekte einer selbsterstellten Klasse erzeugen on Mon, 21 Oct 2013 14:31:30 GMT]]></title><description><![CDATA[<p>Hallo liebe Community,</p>
<p>Ich bin absoluter C++ Neuling und würde gerne mehrere Objekte der Klasse &quot;FullMatrix&quot; erstellen, die jemand anderer geschrieben und mir zur Verfügung gestellt hat (siehe unten). Seltsamerweise funktioniert die Erstellung EINES Objektes problemlos, d.h. folgendes Codebeispiel wird ohne Fehler kompiliert:</p>
<pre><code>#include &quot;MatrixReal.hh&quot;

int main (int argc, char **argv) {
   int m = 4;
   int n = 3;
   FullMatrix matrix1(m,n);
   return 0;
}
</code></pre>
<p>Sobald ich jedoch zwei oder mehrere Objekte erzeugen will...</p>
<pre><code>#include &quot;MatrixReal.hh&quot;

int main (int argc, char **argv) {
   int m = 4;
   int n = 3;
   FullMatrix matrix1(m,n);
   FullMatrix matrix2(m,n);
   return 0;
}
</code></pre>
<p>...bekomme ich vom Compiler (g++) die folgende Fehlermeldung:</p>
<blockquote>
<p>/tmp/ccj3K052.o: In function <code>FullMatrix::~FullMatrix()': test.c:(.text.\_ZN10FullMatrixD2Ev\[\_ZN10FullMatrixD5Ev\]+0x7): undefined reference to</code>vtable for FullMatrix'<br />
/tmp/ccj3K052.o: In function <code>FullMatrix::~FullMatrix()': test.c:(.text.\_ZN10FullMatrixD0Ev\[\_ZN10FullMatrixD5Ev\]+0x7): undefined reference to</code>vtable for FullMatrix'<br />
/tmp/ccj3K052.o: In function <code>main': test.c:(.text.startup+0x1e): undefined reference to</code>vtable for FullMatrix'<br />
test.c:(.text.startup+0x46): undefined reference to `vtable for FullMatrix'<br />
collect2: ld returned 1 exit status<br />
make: *** [TestProg] Error 1</p>
</blockquote>
<p>Kann mir bitte jemand sagen, was genau ich falsch mache?</p>
<pre><code>#ifndef MATRIX_REAL_HH
#define MATRIX_REAL_HH

#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;ArrayReal.hh&gt;

class MatrixReal {
  public:

    const int m, n;

    MatrixReal(int lns, int cls) : m(lns), n(cls) {}

    MatrixReal(int lc) : m(lc), n(lc) {}

    virtual void            multiply_addto(const ArrayReal &amp;vec,
                                                 ArrayReal &amp;result) const = 0;

    void multiply(const ArrayReal &amp;vec, ArrayReal &amp;result) const {
      result = ZeroVector();
      multiply_addto(vec, result);
    }

    virtual ~MatrixReal(){}
};

/*******************************************************************************

*******************************************************************************/
class FullMatrix : public MatrixReal {
  public:

    Real * const ptr;

    FullMatrix(int m, int n) : MatrixReal(m, n), ptr(new Real[m * n]) {}
    FullMatrix(int m) : MatrixReal(m), ptr(new Real[m * m]) {}
    FullMatrix(const FullMatrix &amp;src);
    void operator = (const FullMatrix &amp;src);
    virtual ~FullMatrix() { delete [] ptr; }

    Real &amp; operator () (int i, int j) { return ptr[n * i + j]; }

    Real operator () (int i, int j) const { return ptr[n * i + j]; }

    void multiply_addto(const ArrayReal &amp;vec,
                              ArrayReal &amp;result) const;

    void invert();
    void invert_and_store(FullMatrix &amp;inv);
};

#endif // MATRIX_REAL_HH
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2361875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361875</guid><dc:creator><![CDATA[Unkenbold]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:31:30 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Objekte einer selbsterstellten Klasse erzeugen on Mon, 21 Oct 2013 14:41:44 GMT]]></title><description><![CDATA[<p>Ich vermute mal, dass FullMatrix::multiply_addto auch noch irgendwo definiert werden sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2361879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361879</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:41:44 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Objekte einer selbsterstellten Klasse erzeugen on Mon, 21 Oct 2013 14:46:24 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Ich vermute mal, dass FullMatrix::multiply_addto auch noch irgendwo definiert werden sollte.</p>
</blockquote>
<p>Ja, das habe ich in dem Code, den ich bekommen habe auch schon vergeblich gesucht, aber diese Funktion habe ich bisher ja gar nicht benutzt. Es geht mir momentan wirklich nur ums reine Erzeugen mehrerer Objekte wie oben beschrieben und nicht darum die Funktion multiply_addto zu nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2361882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361882</guid><dc:creator><![CDATA[Unkenbold]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:46:24 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Objekte einer selbsterstellten Klasse erzeugen on Mon, 21 Oct 2013 14:48:58 GMT]]></title><description><![CDATA[<p>Naja, er kann die virtuelle Funktionstabelle halt nicht bauen, wenn er nicht alle virtuellen Funktionen kennt. Warum er die vtable erst bei zwei Objekten haben will, kann ich dir aber auch nicht sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2361883</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361883</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:48:58 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Objekte einer selbsterstellten Klasse erzeugen on Mon, 21 Oct 2013 14:55:55 GMT]]></title><description><![CDATA[<p>Ah ok, habe dann die Funktionen erstmal aus der MatrixReal.hh rausgeschmissen so lange ich sie nicht brauche und nun lassen sich tatsächlich auch mehrere Objekte erstellen. Danke für die schnelle Hilfe <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2361884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2361884</guid><dc:creator><![CDATA[Unkenbold]]></dc:creator><pubDate>Mon, 21 Oct 2013 14:55:55 GMT</pubDate></item></channel></rss>