<?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[Problem mit Array in Konstruktor]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe eine Programmieraufgabe bekommen, die mit Automaten zu tun hat. Man gibt eine Zeile ein, die 3 Zahlen enthält. Sind diese ungleich 0 0 0, so wird ein neues Objekt vom Typ Automat angelegt, welches diese 3 Zahlen enthält, und dann noch ein einfaches, und ein 2dimesionales Array. In dieses will ich nun Werte einfügen, und genau daran scheitere ich. Hier mein Code soweit:</p>
<p>Main.cpp:</p>
<pre><code class="language-cpp">#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &quot;Automat.h&quot;

using namespace std;

int main(int argc, char *argv[])
{   
    char buffy[100];
    cin.get (buffy,80);

    int  k=0, m=0, n=0;
    sscanf(buffy,&quot; %d %d %d &quot;, &amp;k, &amp;m, &amp;n);

    Automat *automat = new Automat(k,m,n);

    automat-&gt;insertQa(automat, 1, 0);
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Automat.h:</p>
<pre><code class="language-cpp">#ifndef _AUTOMAT_H
#define _AUTOMAT_H

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

using namespace std;

class Automat 
{    
public:
             Automat(const int k1, const int m1, const int n1);

             void Automat::insertQa(Automat *automat, int QaZeile, int Qa);

/*
private:  int k,m,n;
          int Qa[m];
          int Delta[n][2];
*/
};

#endif
</code></pre>
<p>Automat.cpp:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

#include &quot;Automat.h&quot;

using namespace std;

Automat::Automat(const int k1, const int m1, const int n1) {
    int k=k1;
    int m=m1;
    int n=n1;                                                 
    int Qa[m];
    int Delta[n][2];
};

void Automat::insertQa(Automat *automat, int QaZeile, int QaEintrag) {
     automat-&gt;Qa[QaZeile]=QaEintrag;
};
</code></pre>
<p>Wenn die Eingabe fertig ist (es fehlen noch die Eingabeaufforderungen), geht es wieder von vorne los, bis irgendwann die erste Zeile 0 0 0 lautet. Es können also mehrere Objekte vom Typ Automat erzeugt werden.<br />
Aber wie kann ich nun etwas in die Array einfügen? Mein Compiler sagt mir immer:</p>
<p>17 Automat.cpp 'class Automat' has no member named 'Qa'</p>
<p>Wie muss das in der Automat.h im privat Bereich aussehen, damit er das kennt, und ich dann endlich Zugriff auf die Elemente habe? Ist das überhaupt soweit richtig?</p>
<p>Bitte helft mir, ich komme einfach nicht weiter, und ich habe nicht mehr allzuviel Zeit für das Projekt!</p>
<p>Vielen Dank im Voraus!!!!!</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/165395/problem-mit-array-in-konstruktor</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 13:27:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/165395.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Nov 2006 14:18:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 14:18:39 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe eine Programmieraufgabe bekommen, die mit Automaten zu tun hat. Man gibt eine Zeile ein, die 3 Zahlen enthält. Sind diese ungleich 0 0 0, so wird ein neues Objekt vom Typ Automat angelegt, welches diese 3 Zahlen enthält, und dann noch ein einfaches, und ein 2dimesionales Array. In dieses will ich nun Werte einfügen, und genau daran scheitere ich. Hier mein Code soweit:</p>
<p>Main.cpp:</p>
<pre><code class="language-cpp">#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &quot;Automat.h&quot;

using namespace std;

int main(int argc, char *argv[])
{   
    char buffy[100];
    cin.get (buffy,80);

    int  k=0, m=0, n=0;
    sscanf(buffy,&quot; %d %d %d &quot;, &amp;k, &amp;m, &amp;n);

    Automat *automat = new Automat(k,m,n);

    automat-&gt;insertQa(automat, 1, 0);
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>Automat.h:</p>
<pre><code class="language-cpp">#ifndef _AUTOMAT_H
#define _AUTOMAT_H

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

using namespace std;

class Automat 
{    
public:
             Automat(const int k1, const int m1, const int n1);

             void Automat::insertQa(Automat *automat, int QaZeile, int Qa);

/*
private:  int k,m,n;
          int Qa[m];
          int Delta[n][2];
*/
};

#endif
</code></pre>
<p>Automat.cpp:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

#include &quot;Automat.h&quot;

using namespace std;

Automat::Automat(const int k1, const int m1, const int n1) {
    int k=k1;
    int m=m1;
    int n=n1;                                                 
    int Qa[m];
    int Delta[n][2];
};

void Automat::insertQa(Automat *automat, int QaZeile, int QaEintrag) {
     automat-&gt;Qa[QaZeile]=QaEintrag;
};
</code></pre>
<p>Wenn die Eingabe fertig ist (es fehlen noch die Eingabeaufforderungen), geht es wieder von vorne los, bis irgendwann die erste Zeile 0 0 0 lautet. Es können also mehrere Objekte vom Typ Automat erzeugt werden.<br />
Aber wie kann ich nun etwas in die Array einfügen? Mein Compiler sagt mir immer:</p>
<p>17 Automat.cpp 'class Automat' has no member named 'Qa'</p>
<p>Wie muss das in der Automat.h im privat Bereich aussehen, damit er das kennt, und ich dann endlich Zugriff auf die Elemente habe? Ist das überhaupt soweit richtig?</p>
<p>Bitte helft mir, ich komme einfach nicht weiter, und ich habe nicht mehr allzuviel Zeit für das Projekt!</p>
<p>Vielen Dank im Voraus!!!!!</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177178</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Sun, 19 Nov 2006 14:18:39 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 14:24:49 GMT]]></title><description><![CDATA[<p>Ähm warum hast Du das auskommentiert ? *sich-wunder*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177187</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sun, 19 Nov 2006 14:24:49 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 14:34:37 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>weil mir dann der Compiler immer einen Fehler gibt:</p>
<p>28 Automat.h invalid use of non-static data member <code>Automat::m' 29 Automat.h from this location 28 Automat.h invalid use of non-static data member</code>Automat::n'<br />
30 Automat.h from this location<br />
Automat.cpp In member function `void Automat::insertQa(Automat*, int, int)':</p>
<p>Er meint damit das m und das n, was in den beiden Array's vorkommt. Wie bekomme ich das denn in den Griff?</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177195</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Sun, 19 Nov 2006 14:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 14:38:52 GMT]]></title><description><![CDATA[<p>Die lokalen Variablen, die du im Konstruktor anlegst, verdecken deine Member. Ist vermutlich nicht beabsichtig.</p>
<p>Und warum bekommt deine insertQa-Methode einen Zeiger auf Automat mit? Wäre es nicht sinnvoller, wenn sie das, was sie tut, mit dem Objekt tun würde, zu dem sie gehört?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177197</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sun, 19 Nov 2006 14:38:52 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 14:47:53 GMT]]></title><description><![CDATA[<p>Ozzy schrieb:</p>
<blockquote>
<p>Aber wie kann ich nun etwas in die Array einfügen? Mein Compiler sagt mir immer:<br />
[...]</p>
</blockquote>
<p>Hm. Ich frage mich grad ob das ein Fortschritt oder Rückschritt gegenüber den Leuten die keine Fehlermeldungen liefern ist.</p>
<pre><code class="language-cpp">// Automat.hpp

class Automat
{
  //...
  std::vector&lt;int&gt;  Qa;
  std::vector&lt;std::vector&lt;int&gt; &gt;  Delta;
};

// Automat.cpp

using std::vector;

Automat::Automat(const int k1, const int m1, const int n1)
  : k(k1)
  , m(m1)
  , n(n1)
  , Qa(m1)
  , Delta(n1, vector&lt;int&gt;(2))
{
/* Das sind lokale Variablen, nicht deine Member!
    int k=k1;
    int m=m1;
    int n=n1;                                                
    int Qa[m];
    int Delta[n][2];
*/
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1177205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177205</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Sun, 19 Nov 2006 14:47:53 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 14:50:50 GMT]]></title><description><![CDATA[<p>Die Anzahl der Array-Elemente muss ein konstanter Ausdruck sein.<br />
Für eine dynamische Speicherverwaltung benutze lieber vektoren oder halt Pointer auf Arrays.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177207</guid><dc:creator><![CDATA[uljanow]]></dc:creator><pubDate>Sun, 19 Nov 2006 14:50:50 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 15:02:49 GMT]]></title><description><![CDATA[<p>Also kein Array sondern lieber Verktoren; sehe ich das richtig?<br />
Schade, dabei wäre es mit Array's so schön gewesen...</p>
<p>Noch eine Frage: wie schreibe ich denn in einen Vektor in einem Vektor? So etwas habe ich noch nie gemacht...</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177210</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Sun, 19 Nov 2006 15:02:49 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 15:21:23 GMT]]></title><description><![CDATA[<p>Hallo</p>
<pre><code class="language-cpp">std::vector&lt;std::vector&lt;int&gt; &gt; myarray; // Leerzeichen zwischen den &gt; &gt; beachten!
myarray.push_back(std::vector&lt;int&gt;());
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177225</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sun, 19 Nov 2006 15:21:23 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 15:26:14 GMT]]></title><description><![CDATA[<p>Dann muss ich mir also einen &quot;Hilfsvektor&quot; bauen, den vollmachen, und dann den ganzen Vektor in den &quot;äußeren&quot; Vektor schieben?</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177231</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Sun, 19 Nov 2006 15:26:14 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 15:36:41 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">typedef std::vector&lt;int&gt; Int1D;
typedef std::vector&lt;Int1D&gt; Int2D;

Int2D nullmatrix(10, Int1D(10,0));

// bzw.

for (int i = 0; i &lt; nullmatrix.size(); i++) {
    for (int j = 0; j &lt; nullmatrix[i].size(); j++)
        nullmatrix[i][j] = 1;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1177233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177233</guid><dc:creator><![CDATA[uljanow]]></dc:creator><pubDate>Sun, 19 Nov 2006 15:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 15:29:37 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Automat::Automat(const int k1, const int m1, const int n1)
  : k(k1)
  , m(m1)
  , n(n1)
  , Qa(m1)
  , Delta(n1, vector&lt;int&gt;(2)) // &lt;--- erstellt ein n1*2 Array
{
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1177235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177235</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Sun, 19 Nov 2006 15:29:37 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 18:55:18 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>kann mir jemand von Euch sagen, warum das (anscheinend) nicht funktioniert:</p>
<pre><code class="language-cpp">void Automat::Automat::insertDelta(Automat *automat, vector&lt;int&gt; Zustand) {
     automat-&gt;Delta.push_back(Zustand);
};
</code></pre>
<p>Zumindest hatte ich probiert, mit:</p>
<pre><code class="language-cpp">void Automat::ausgeben(Automat *automat) {
     cout &lt;&lt; automat-&gt;Delta[0][0] &lt;&lt; &quot; &quot; &lt;&lt; automat-&gt;Delta[0][1] &lt;&lt; &quot; &quot; &lt;&lt; automat-&gt;Delta[0][2] &lt;&lt; endl &lt;&lt; endl;
};
</code></pre>
<p>mir etwas ausgeben zu lassen, aber ich bekomme immer nur 0 0 0 raus. Der Vector Zustand wir der insertDelta aber richtig übergeben, das hatte ich schon ausprobiert.</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177366</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Sun, 19 Nov 2006 18:55:18 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 19:18:31 GMT]]></title><description><![CDATA[<p>Kannst du sagen, warum du innerhalb von Automat offenbar noch einen Typ Automat hast? Und warum offenbar alle deine Memberfunktionen auf dem übergebenen Automat-Zeiger arbeiten statt auf this?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177374</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sun, 19 Nov 2006 19:18:31 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 19:20:52 GMT]]></title><description><![CDATA[<p>Nein, das kann ich Dir leider nicht sagen <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>
<p>Aber ist das eine Erklärung für die Frage?<br />
MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177375</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Sun, 19 Nov 2006 19:20:52 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Sun, 19 Nov 2006 19:46:47 GMT]]></title><description><![CDATA[<p>Wie sieht denn dein tatsächlicher Code jetzt aus? Und warum weißt du nicht was du machst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177386</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177386</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Sun, 19 Nov 2006 19:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Mon, 20 Nov 2006 06:39:14 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Scherz beiseite, ich hatte einfach nicht dran gedacht. Nun habe ich this-&gt; statt automat-&gt; genommen, aber das löst nicht mein Problem. Hast Du vielleicht noch eine Idee?</p>
<p>MfG, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177534</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Mon, 20 Nov 2006 06:39:14 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Array in Konstruktor on Mon, 20 Nov 2006 06:54:25 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe es jetzt selbst herausgefunden; ich dachte, ich müsse ein push_back auf dem Vektor ausführen, deshalb wurden meine Elemente immer nur hinten dran gehängt, und somit kam natürlich bei der Abfrage der ersten Elemente immer nur 0 0 0 raus.<br />
Mit der Zuweisung aber funktioniert es jetzt.</p>
<p>Trotzdem vielen Dank, Ozzy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1177545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1177545</guid><dc:creator><![CDATA[Ozzy]]></dc:creator><pubDate>Mon, 20 Nov 2006 06:54:25 GMT</pubDate></item></channel></rss>