<?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[Dynamische Anzahl von Istanzen einer Klasse anlegen.]]></title><description><![CDATA[<p>Hallo zusammen, ich habe mal eine Frage:</p>
<p>Ich möchte gerne eine dynamische Anzahl von Instanzen einer Klasse anlegen ich bekomme nun einen Speicherfehler, da ich vermute, dass der Standardkonstuktor aufgerufen wird, der aber noch keinen Speicher für die Variablen der Klasse reserviert hat.</p>
<p>Hat jemand eine Idee wie ich das Problem lösen kann?</p>
<p>Hier mal der Code:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;

using namespace std;

// Klassendefinition
class Student {

private:
	//Variablen deklarieren
	string *sMatrikel;
	string *sVorname;
	string *sNachname;
	string *sStudiengang;
	int *iAlter;

public:
	//Funktionen deklarieren
	Student( const char *const sV, const char *const sN, const char *const sM, const char *const sS, int const iA); 
	Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS);
	Student::Student(const char *const sV, const char *const sN, const char *const sM);
	Student::Student(const char *const sV, const char *const sN);
	Student::Student(const char *const sV);
	Student::Student();
	~Student();
	void einlesen();
	void ausgeben();

	//Set Variablen ???

};

//Definition der Memberfunktionen
// Konstruktor mit allen Varianten von Übergebenen Parametern

Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS, int const iA) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
	//Speicher für die Matrikelnummer reservieren
	sMatrikel = new string(sM);
	//Speicher für das Alter reservieren
	sStudiengang = new string(sS);
	//Speicher für Alter reservieren
	iAlter = new int(iA);
}

Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
	//Speicher für die Matrikelnummer reservieren
	sMatrikel = new string(sM);
	//Speicher für das Alter reservieren
	sStudiengang = new string(sS);
}

Student::Student(const char *const sV, const char *const sN, const char *const sM) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
	//Speicher für die Matrikelnummer reservieren
	sMatrikel = new string(sM);
}

Student::Student(const char *const sV, const char *const sN) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
}

Student::Student(const char *const sV) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
}

Student::Student() {

}

//Destruktor
	Student::~Student() {
		delete sVorname;
		delete sNachname;
		delete sMatrikel;
		delete sStudiengang;
		delete iAlter;
	}

//Einslesen von Studenten Infos
	void Student::einlesen() {
		cout &lt;&lt; &quot;Bitte Vorname eingeben &quot; ;
		cin &gt;&gt; *sVorname;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Nachname eingeben &quot;;
		cin &gt;&gt; *sNachname;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Matrikelnummer eingeben: &quot;;
		cin &gt;&gt; *sMatrikel;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Studiengang eingeben: &quot;;
		cin &gt;&gt; *sStudiengang;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Alter eingeben: &quot;;
		cin &gt;&gt; *iAlter;
	}

//Ausgabe von Studenten Infos
	void Student::ausgeben() {
		cout &lt;&lt; &quot;Vorname: &quot; &lt;&lt; *sVorname &lt;&lt; endl;
		cout &lt;&lt; &quot;Nachname: &quot; &lt;&lt; *sNachname &lt;&lt; endl;
		cout &lt;&lt; &quot;Matrikelnummer: &quot; &lt;&lt; *sMatrikel &lt;&lt; endl;
		cout &lt;&lt; &quot;Studiengang: &quot; &lt;&lt; *sStudiengang &lt;&lt; endl;
		cout &lt;&lt; endl;
		cout &lt;&lt; &quot;Alter: &quot; &lt;&lt; *iAlter &lt;&lt; endl;
		cout &lt;&lt; endl;
	}

int main() {

	Student *student = new Student;

	int iAnzahl;

	// Anzahl der zu erstellenden Studenten einlesen
	cout &lt;&lt; &quot;Wieviele Studenten wollen Sie anlegen? : &quot;;
	cin &gt;&gt; iAnzahl;
	cout &lt;&lt; &quot;Sie wollen &quot; &lt;&lt; iAnzahl &lt;&lt;&quot; Studenten anlegen!&quot; &lt;&lt; endl;

	for (int i=1; i&lt;=iAnzahl; i++) {
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte &quot; &lt;&lt; i &lt;&lt; &quot;. Student anlegen:&quot; &lt;&lt; endl;
		student[i].einlesen();
	}

	/*Student Student4(&quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, 0);

	Student4.einlesen();
	Student Student1(&quot;Max&quot;, &quot;Mustermann&quot;, &quot;01234&quot;, &quot;IT&quot;, 45);
	Student Student2(&quot;Karl&quot;, &quot;Mustermann&quot;, &quot;01223&quot;, &quot;ET&quot;, 23);
	Student Student3(&quot;Fritz&quot;, &quot;Mustermann&quot;, &quot;44562&quot;, &quot;DM&quot;, 24);

	Student1.ausgeben();
	Student2.ausgeben();
	Student3.ausgeben();
	Student4.ausgeben();*/

		delete student;

	_getch();
	return 0;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/318330/dynamische-anzahl-von-istanzen-einer-klasse-anlegen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 10:49:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318330.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Jul 2013 19:21:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 19:21:00 GMT]]></title><description><![CDATA[<p>Hallo zusammen, ich habe mal eine Frage:</p>
<p>Ich möchte gerne eine dynamische Anzahl von Instanzen einer Klasse anlegen ich bekomme nun einen Speicherfehler, da ich vermute, dass der Standardkonstuktor aufgerufen wird, der aber noch keinen Speicher für die Variablen der Klasse reserviert hat.</p>
<p>Hat jemand eine Idee wie ich das Problem lösen kann?</p>
<p>Hier mal der Code:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;

using namespace std;

// Klassendefinition
class Student {

private:
	//Variablen deklarieren
	string *sMatrikel;
	string *sVorname;
	string *sNachname;
	string *sStudiengang;
	int *iAlter;

public:
	//Funktionen deklarieren
	Student( const char *const sV, const char *const sN, const char *const sM, const char *const sS, int const iA); 
	Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS);
	Student::Student(const char *const sV, const char *const sN, const char *const sM);
	Student::Student(const char *const sV, const char *const sN);
	Student::Student(const char *const sV);
	Student::Student();
	~Student();
	void einlesen();
	void ausgeben();

	//Set Variablen ???

};

//Definition der Memberfunktionen
// Konstruktor mit allen Varianten von Übergebenen Parametern

Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS, int const iA) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
	//Speicher für die Matrikelnummer reservieren
	sMatrikel = new string(sM);
	//Speicher für das Alter reservieren
	sStudiengang = new string(sS);
	//Speicher für Alter reservieren
	iAlter = new int(iA);
}

Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
	//Speicher für die Matrikelnummer reservieren
	sMatrikel = new string(sM);
	//Speicher für das Alter reservieren
	sStudiengang = new string(sS);
}

Student::Student(const char *const sV, const char *const sN, const char *const sM) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
	//Speicher für die Matrikelnummer reservieren
	sMatrikel = new string(sM);
}

Student::Student(const char *const sV, const char *const sN) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
	// Speicher für den Nachname reservieren
	sNachname = new string(sN);
}

Student::Student(const char *const sV) {
	// Speicher für den Vornamen reservieren
	sVorname = new string(sV);
}

Student::Student() {

}

//Destruktor
	Student::~Student() {
		delete sVorname;
		delete sNachname;
		delete sMatrikel;
		delete sStudiengang;
		delete iAlter;
	}

//Einslesen von Studenten Infos
	void Student::einlesen() {
		cout &lt;&lt; &quot;Bitte Vorname eingeben &quot; ;
		cin &gt;&gt; *sVorname;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Nachname eingeben &quot;;
		cin &gt;&gt; *sNachname;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Matrikelnummer eingeben: &quot;;
		cin &gt;&gt; *sMatrikel;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Studiengang eingeben: &quot;;
		cin &gt;&gt; *sStudiengang;
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte Alter eingeben: &quot;;
		cin &gt;&gt; *iAlter;
	}

//Ausgabe von Studenten Infos
	void Student::ausgeben() {
		cout &lt;&lt; &quot;Vorname: &quot; &lt;&lt; *sVorname &lt;&lt; endl;
		cout &lt;&lt; &quot;Nachname: &quot; &lt;&lt; *sNachname &lt;&lt; endl;
		cout &lt;&lt; &quot;Matrikelnummer: &quot; &lt;&lt; *sMatrikel &lt;&lt; endl;
		cout &lt;&lt; &quot;Studiengang: &quot; &lt;&lt; *sStudiengang &lt;&lt; endl;
		cout &lt;&lt; endl;
		cout &lt;&lt; &quot;Alter: &quot; &lt;&lt; *iAlter &lt;&lt; endl;
		cout &lt;&lt; endl;
	}

int main() {

	Student *student = new Student;

	int iAnzahl;

	// Anzahl der zu erstellenden Studenten einlesen
	cout &lt;&lt; &quot;Wieviele Studenten wollen Sie anlegen? : &quot;;
	cin &gt;&gt; iAnzahl;
	cout &lt;&lt; &quot;Sie wollen &quot; &lt;&lt; iAnzahl &lt;&lt;&quot; Studenten anlegen!&quot; &lt;&lt; endl;

	for (int i=1; i&lt;=iAnzahl; i++) {
		cout &lt;&lt; endl &lt;&lt; &quot;Bitte &quot; &lt;&lt; i &lt;&lt; &quot;. Student anlegen:&quot; &lt;&lt; endl;
		student[i].einlesen();
	}

	/*Student Student4(&quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, 0);

	Student4.einlesen();
	Student Student1(&quot;Max&quot;, &quot;Mustermann&quot;, &quot;01234&quot;, &quot;IT&quot;, 45);
	Student Student2(&quot;Karl&quot;, &quot;Mustermann&quot;, &quot;01223&quot;, &quot;ET&quot;, 23);
	Student Student3(&quot;Fritz&quot;, &quot;Mustermann&quot;, &quot;44562&quot;, &quot;DM&quot;, 24);

	Student1.ausgeben();
	Student2.ausgeben();
	Student3.ausgeben();
	Student4.ausgeben();*/

		delete student;

	_getch();
	return 0;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2337552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337552</guid><dc:creator><![CDATA[Tyle]]></dc:creator><pubDate>Mon, 08 Jul 2013 19:21:00 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 19:28:15 GMT]]></title><description><![CDATA[<p>[quote=&quot;Tyle&quot;]<br />
Ich möchte gerne eine dynamische Anzahl von Instanzen einer Klasse anlegen[/quote[<br />
=&gt; std::vector</p>
<blockquote>
<p>ich bekomme nun einen Speicherfehler, da ich vermute, dass der Standardkonstuktor aufgerufen wird, der aber noch keinen Speicher für die Variablen der Klasse reserviert hat.</p>
</blockquote>
<p>Nö, in der main holst du dir ein Element, benutzt aber anzahl Elemente, was nicht klappen kann.<br />
Benutze hierfür std::vector, da passiert so etwas nicht.<br />
Und warum forderst du den Speicher für die Strings manuell an?<br />
Das macht man nur in Java.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337554</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337554</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 08 Jul 2013 19:28:15 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 19:33:53 GMT]]></title><description><![CDATA[<pre><code>...
#include &lt;vector&gt;

...

int main() {

    int iAnzahl;

    // Anzahl der zu erstellenden Studenten einlesen
    cout &lt;&lt; &quot;Wieviele Studenten wollen Sie anlegen? : &quot;;
    cin &gt;&gt; iAnzahl;
    cout &lt;&lt; &quot;Sie wollen &quot; &lt;&lt; iAnzahl &lt;&lt;&quot; Studenten anlegen!&quot; &lt;&lt; endl;

vector&lt;student&gt; studenten;

    for (int i=1; i&lt;=iAnzahl; i++) {
        cout &lt;&lt; endl &lt;&lt; &quot;Bitte &quot; &lt;&lt; i &lt;&lt; &quot;. Student anlegen:&quot; &lt;&lt; endl;
        student tmp;
        tmp.einlesen();
        studenten.push_back(tmp);
    }
    for(int i = 0; i &lt; studenten.size(); ++i)
        studenten[i].ausgeben();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2337556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337556</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 08 Jul 2013 19:33:53 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 19:34:52 GMT]]></title><description><![CDATA[<p>Tyle schrieb:</p>
<blockquote>
<p>Ich möchte gerne eine dynamische Anzahl von Instanzen einer Klasse anlegen ich bekomme nun einen Speicherfehler, da ich vermute, dass der Standardkonstuktor aufgerufen wird, der aber noch keinen Speicher für die Variablen der Klasse reserviert hat.</p>
<p>Hat jemand eine Idee wie ich das Problem lösen kann?</p>
<p>Hier mal der Code:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;

using namespace std;

// Klassendefinition
class Student {

private:
	//Variablen deklarieren
	string *sMatrikel;
	string *sVorname;
	string *sNachname;
	string *sStudiengang;
	int *iAlter;

public:
	//Funktionen deklarieren
	Student( const char *const sV, const char *const sN, const char *const sM, const char *const sS, int const iA); 
	Student::Student(const char *const sV, const char *const sN, const char *const sM, const char *const sS);
	Student::Student(const char *const sV, const char *const sN, const char *const sM);
	Student::Student(const char *const sV, const char *const sN);
	Student::Student(const char *const sV);
	Student::Student();
	~Student();
	void einlesen();
	void ausgeben();

	//Set Variablen ???
};
</code></pre>
</blockquote>
<p>Stopp stopp stopp ... Das kann man ja nicht mit ansehen ...</p>
<p>Wie wärs mit</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;utility&gt;

struct Student
{
   std::string matrikel;
   std::string vorname;
   std::string nachname;
   std::string studiengang;
   int geburtsjahr;

   Student(std::string m, std::string v,
      std::string n, std::string s, int gj)
   : matrikel   (std::move(m))
   , vorname    (std::move(v))
   , nachname   (std::move(n))
   , studiengang(std::move(s))
   , geburtsjahr(gj)
   {}
};

int main()
{
   std::vector&lt;Student&gt; studenten;
   studenten.emplace_back(&quot;12345&quot;,&quot;Hans&quot;,&quot;Wurst&quot;,&quot;Fleicherlogie&quot;,1990);
   studenten.emplace_back(&quot;54321&quot;,&quot;Klaus&quot;,&quot;Kinski&quot;,&quot;Ausrasteratik&quot;,1950);
}
</code></pre>
<p>Nein, du brauchst normalerweise nicht so viele Zeiger als Datenelemente in einer Klasse. Die machen nur Ärger. Und es macht auch wenig Sinn, eine reine &quot;Daten-Klasse&quot; mit privaten Elementen und dafür getter/setter zu bauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337558</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 08 Jul 2013 19:34:52 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 19:46:17 GMT]]></title><description><![CDATA[<p>Die Zeiger waren die Anforderung. Bin noch dabei das Klassenkonzept zu lernen.</p>
<p>Ist meine erste Klasse <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337563</guid><dc:creator><![CDATA[Tyle]]></dc:creator><pubDate>Mon, 08 Jul 2013 19:46:17 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 19:55:06 GMT]]></title><description><![CDATA[<p>Tyle schrieb:</p>
<blockquote>
<p>Die Zeiger waren die Anforderung.</p>
</blockquote>
<p>Ich bin mir sehr sicher, dass du das falsch verstanden hast. Zeiger auf std::string machen 0 Sinn.</p>
<p>Hmm, Zeiger auf Zeichenketten...<br />
Bist du sicher, dass du C++ machst, kein C? Wird oft verwechselt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337565</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 08 Jul 2013 19:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 20:22:08 GMT]]></title><description><![CDATA[<p>Stimmt, die Zeiger waren nicht unbedingt erfordert.<br />
Und ja es ist C++... sonst würden ja keine Klassen vorkommen.</p>
<p>Der Code funktioniert aber auch nicht. Habe das mal ausprobiert, bekomme dort auch ne Fehlermeldung vom Speicher bei der Ausführung:</p>
<pre><code>#include &lt;vector&gt;

...

int main() {

    int iAnzahl;

    // Anzahl der zu erstellenden Studenten einlesen
    cout &lt;&lt; &quot;Wieviele Studenten wollen Sie anlegen? : &quot;;
    cin &gt;&gt; iAnzahl;
    cout &lt;&lt; &quot;Sie wollen &quot; &lt;&lt; iAnzahl &lt;&lt;&quot; Studenten anlegen!&quot; &lt;&lt; endl;

vector&lt;Student&gt; studenten;

    for (int i=1; i&lt;=iAnzahl; i++) {
        cout &lt;&lt; endl &lt;&lt; &quot;Bitte &quot; &lt;&lt; i &lt;&lt; &quot;. Student anlegen:&quot; &lt;&lt; endl;
        Student tmp;
        tmp.einlesen();
        studenten.push_back(tmp);
    }
    for(int i = 0; i &lt; studenten.size(); ++i)
        studenten[i].ausgeben();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2337569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337569</guid><dc:creator><![CDATA[Tyle]]></dc:creator><pubDate>Mon, 08 Jul 2013 20:22:08 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Mon, 08 Jul 2013 21:35:34 GMT]]></title><description><![CDATA[<p>Wie sehen Student und Student::einlesen aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337585</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 08 Jul 2013 21:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 07:03:18 GMT]]></title><description><![CDATA[<p>Tyle schrieb:</p>
<blockquote>
<p>Die Zeiger waren die Anforderung. Bin noch dabei das Klassenkonzept zu lernen.</p>
<p>Ist meine erste Klasse <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Du hast viel zuviele Sterne ---&gt; das mit den Zeigern ist Mist. Wenn das die - bescheuerte - Anforderung ist, lern erst das Zeigerkonzept.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337609</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Tue, 09 Jul 2013 07:03:18 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 07:22:55 GMT]]></title><description><![CDATA[<p>Das ist megamässig schlechter C++ Stil den euer Professor euch da beibringt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337612</guid><dc:creator><![CDATA[std__student]]></dc:creator><pubDate>Tue, 09 Jul 2013 07:22:55 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 13:41:15 GMT]]></title><description><![CDATA[<p>Der Lehrstuhl von OOP ist wirklich nicht sonderlich gut. Das mussten wir leider auch schon feststellen.</p>
<p>So ich habe mich nochmal drangesetzt und das Programm jetzt vernünftig geschrieben und auch wesentlich unkomplizierter.</p>
<p>Das mit den Zeigern habe ich falsch verstanden und ist daher auf meinen Mist gewachsen.</p>
<p>Hier das Programm:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

class Student {
public:
	void einlesen();
	void ausgeben();
	Student();
	~Student();

private:
	string vorname_;
	string nachname_;
	string matrikel_;
	string studiengang_;
	int alter_;

};

void Student::einlesen() {
	cout &lt;&lt; &quot;Bitte Vornamen eingeben: &quot;;
	cin &gt;&gt; vorname_;
	cout &lt;&lt;endl &lt;&lt; &quot;Bitte Nachname eingeben: &quot;;
	cin &gt;&gt; nachname_;
	cout &lt;&lt; endl &lt;&lt; &quot;Bitte Matrikelnummer eingeben: &quot;;
	cin &gt;&gt; matrikel_;
	cout &lt;&lt; endl &lt;&lt; &quot;Bitte Studiengang eingeben: &quot;;
	cin &gt;&gt; studiengang_;
	cout &lt;&lt; endl &lt;&lt; &quot;Bitte ihr Alter eingeben: &quot;;
	cin &gt;&gt; alter_;
	cout &lt;&lt; endl;
}

void Student::ausgeben() {
	cout &lt;&lt; matrikel_ &lt;&lt;&quot;, &quot; &lt;&lt; vorname_ &lt;&lt; &quot; &quot; &lt;&lt; nachname_ &lt;&lt; endl;
	cout &lt;&lt; &quot;Alter: &quot; &lt;&lt; alter_ &lt;&lt; &quot; Jahre&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Studiengang: &quot; &lt;&lt; studiengang_ &lt;&lt; endl;
}

//Konstrukor und Destruktor
Student::Student()  {}
Student::~Student() {}

int main () {

	int n;
	cout &lt;&lt; &quot;Bitte die Anzahl der Studenten angeben die Sie anlegen möchten: &quot;;
	cin &gt;&gt; n;
	cout &lt;&lt; endl;

	Student *studenten = new Student[n];

	for (int i=0; i&lt;n; i++) {
		cout &lt;&lt; &quot;Bitte &quot; &lt;&lt; (i+1) &lt;&lt; &quot;. Studenten anlegen!&quot; &lt;&lt; endl;
		studenten[i].einlesen();
	}

		for (int i=0; i&lt;n; i++) {
		studenten[i].ausgeben();
		cout &lt;&lt; endl;
	}

	delete [] studenten;

	system(&quot;pause&quot;);
	return 0;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2337681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337681</guid><dc:creator><![CDATA[Tyle]]></dc:creator><pubDate>Tue, 09 Jul 2013 13:41:15 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 14:03:42 GMT]]></title><description><![CDATA[<p>Wenn dein Konstruktor und Destruktor leer sind, bietet es sich an, diese wegzulassen.<br />
<a href="http://en.wikipedia.org/wiki/Special_member_functions" rel="nofollow">http://en.wikipedia.org/wiki/Special_member_functions</a></p>
<p>Was hier am Design noch ungünstig ist, ist die Vermischung von Schnittstelle und Programmlogik. Ein Student hat keine Konsolenausgabe<sup>*</sup> oder -eingabe, das kannst du leicht an dir selber mal ausprobieren <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="😉"
    /> . Er kann seine Daten irgendwo hinterlassen und als Zugeständnis an die Existenz des Studenten im Computer können diese Daten sicherlich auch wieder gelesen werden. Aber dass dies unbedingt über cin/cout erfolgen soll, das sollte einem Studenten an sich eigentlich einmal egal sein, das gehört nicht zum Studentsein.</p>
<p>Konkret will ich auf Folgendes hinaus, was aber bei Euch wahrscheinlich noch nie drangekommen ist (und vielleicht auch nie wird):<br />
<a href="https://www.google.de/search?&amp;q=c%2B%2B%20overload%20stream%20operator" rel="nofollow">Google: c++ overload stream operator</a></p>
<p><sup>*</sup>: cout und cin stehen natürlich für character out und -in, nicht console. Muss auch praktisch nicht identisch sein, wusste bloß nicht wie ich das auf Deutsch ausdrücken sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337685</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 09 Jul 2013 14:03:42 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 14:54:54 GMT]]></title><description><![CDATA[<blockquote>
<p>Hinweis: Statt der Funktionen eingeben() und ausgeben() sollte man normalerweise einen eigenen Eingabeoperator (operator &gt;&gt;) bzw. Ausgabeoperator (operator &lt;&lt;) benutzen oder die Daten direkt im Konstruktor belegen. Da diese Aufgabe aber nur als vereinfachter Einstieg dienen soll, werden hier noch keine Operatoren und Konstruktoren verwendet.</p>
</blockquote>
<p>Meinst du das? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Kommt wohl noch später, bin jetzt gerade an der nächsten Klasse dran, die schon was umfangreicher wird und auch das header Prinzip umfasst.</p>
<p>Edit:<br />
Später ist wohl jetzt, ab jetzt muss ich die Überladung der Stream-Operatoren lernen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337690</guid><dc:creator><![CDATA[Tyle]]></dc:creator><pubDate>Tue, 09 Jul 2013 14:54:54 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 14:48:04 GMT]]></title><description><![CDATA[<p>Tyle schrieb:</p>
<blockquote>
<p>Meinst du das? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Ja. gut zu wissen, dass es dem Lehrer nicht unbekannt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337701</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 09 Jul 2013 14:48:04 GMT</pubDate></item><item><title><![CDATA[Reply to Dynamische Anzahl von Istanzen einer Klasse anlegen. on Tue, 09 Jul 2013 15:37:14 GMT]]></title><description><![CDATA[<p>Gibt es dazu ein gutes Tutorial, welches das Konzept anschaulich erklärt? Ich brauche das nämlich ab sofort.</p>
<p>Glaube hier wird das gut beschrieben:<br />
<a href="http://www.c-plusplus.net/forum/232010-full" rel="nofollow">http://www.c-plusplus.net/forum/232010-full</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2337703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2337703</guid><dc:creator><![CDATA[Tyle]]></dc:creator><pubDate>Tue, 09 Jul 2013 15:37:14 GMT</pubDate></item></channel></rss>