<?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[Array einer Template Klasse Chain]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Problem mit meinem Programm. Ich soll ein Array mit Listen als Elemente bestücken. Aber irgendwie will dies nicht klappen, ich hab da nen Zeiger-Problem und ich weiß nicht, wie ich dieses lösen kann.<br />
Das erste Array-Element zeigt immer wieder auf sich selber, sodass ich ne Dauerschleife erzeuge.<br />
Hier mal der code</p>
<pre><code class="language-cpp">template &lt;class T&gt;
class Chain{
public:

	friend void Equivalenz();
	template &lt;class S&gt;
	friend ostream&amp; operator&lt;&lt; (ostream &amp; ,const Chain&lt;S&gt;&amp; );
	Chain(T t = 0, Chain&lt;T&gt; *h = NULL): data(t), next(h) {};

private:

	T data;
	Chain&lt;T&gt; *next;

};
template &lt;class T&gt;
ostream&amp; operator&lt;&lt; (ostream &amp; ostr,const Chain&lt;T&gt;&amp; a){

	Chain&lt;T&gt; temp = a;

	while(&amp;temp){

		ostr&lt;&lt;temp.data&lt;&lt;&quot; -&gt; &quot;;
		temp = *temp.next;

	}

	return ostr;
}

void Equivalenz(){

	ifstream inFile(&quot;Eingabe.txt&quot;);	

	int n,j,i;
	inFile &gt;&gt; n &gt;&gt; i &gt;&gt; j;
	cout&lt;&lt;n&lt;&lt;endl;
	cout&lt;&lt;i&lt;&lt;endl&lt;&lt;j&lt;&lt;endl;
	Chain&lt;int&gt; *first = new Chain&lt;int&gt;[n];

	for(int s = 0;s&lt;n;s++) first[s] = NULL;

	while(inFile.good()){

		Chain&lt;int&gt; *a = new Chain&lt;int&gt;(i);
		a-&gt;next = &amp;first[i];
		first[i] = *a;
		Chain&lt;int&gt; * b = new Chain&lt;int&gt;(j);
		b-&gt;next = &amp;first[j];
		first[j] = *b;

		inFile &gt;&gt; i &gt;&gt; j;

	}

	cout&lt;&lt;first[0];

}

int main()
{
	int n;
	Equivalenz();	
	cin&gt;&gt;n;
	return 0;
}
</code></pre>
<p>Ich habe schon einiges Versucht, aber entweder bekomme ich Referenzierungsfehler oder erzeuge wieder meine schöne Dauerschleife.<br />
Ich bin derzeit recht ratlos und ehrlich gesagt auch leicht angefressen <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="😃"
    /><br />
Vllt könnt ihr mir ja helfen !</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/303687/array-einer-template-klasse-chain</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 07:23:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/303687.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 May 2012 13:27:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Array einer Template Klasse Chain on Sun, 20 May 2012 13:37:22 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Problem mit meinem Programm. Ich soll ein Array mit Listen als Elemente bestücken. Aber irgendwie will dies nicht klappen, ich hab da nen Zeiger-Problem und ich weiß nicht, wie ich dieses lösen kann.<br />
Das erste Array-Element zeigt immer wieder auf sich selber, sodass ich ne Dauerschleife erzeuge.<br />
Hier mal der code</p>
<pre><code class="language-cpp">template &lt;class T&gt;
class Chain{
public:

	friend void Equivalenz();
	template &lt;class S&gt;
	friend ostream&amp; operator&lt;&lt; (ostream &amp; ,const Chain&lt;S&gt;&amp; );
	Chain(T t = 0, Chain&lt;T&gt; *h = NULL): data(t), next(h) {};

private:

	T data;
	Chain&lt;T&gt; *next;

};
template &lt;class T&gt;
ostream&amp; operator&lt;&lt; (ostream &amp; ostr,const Chain&lt;T&gt;&amp; a){

	Chain&lt;T&gt; temp = a;

	while(&amp;temp){

		ostr&lt;&lt;temp.data&lt;&lt;&quot; -&gt; &quot;;
		temp = *temp.next;

	}

	return ostr;
}

void Equivalenz(){

	ifstream inFile(&quot;Eingabe.txt&quot;);	

	int n,j,i;
	inFile &gt;&gt; n &gt;&gt; i &gt;&gt; j;
	cout&lt;&lt;n&lt;&lt;endl;
	cout&lt;&lt;i&lt;&lt;endl&lt;&lt;j&lt;&lt;endl;
	Chain&lt;int&gt; *first = new Chain&lt;int&gt;[n];

	for(int s = 0;s&lt;n;s++) first[s] = NULL;

	while(inFile.good()){

		Chain&lt;int&gt; *a = new Chain&lt;int&gt;(i);
		a-&gt;next = &amp;first[i];
		first[i] = *a;
		Chain&lt;int&gt; * b = new Chain&lt;int&gt;(j);
		b-&gt;next = &amp;first[j];
		first[j] = *b;

		inFile &gt;&gt; i &gt;&gt; j;

	}

	cout&lt;&lt;first[0];

}

int main()
{
	int n;
	Equivalenz();	
	cin&gt;&gt;n;
	return 0;
}
</code></pre>
<p>Ich habe schon einiges Versucht, aber entweder bekomme ich Referenzierungsfehler oder erzeuge wieder meine schöne Dauerschleife.<br />
Ich bin derzeit recht ratlos und ehrlich gesagt auch leicht angefressen <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="😃"
    /><br />
Vllt könnt ihr mir ja helfen !</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2213418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213418</guid><dc:creator><![CDATA[ponchosi]]></dc:creator><pubDate>Sun, 20 May 2012 13:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to Array einer Template Klasse Chain on Sun, 20 May 2012 16:02:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>die Abfrage &quot;while(&amp;temp)&quot; ergibt ja auch keinen Sinn.<br />
Wenn du schon mit Zeigern hantierst, dann mußt du diese auch konsequent verwenden:</p>
<pre><code class="language-cpp">const Chain&lt;T&gt; * temp = &amp;a;

    while(temp)
    {
        ostr&lt;&lt;temp-&gt;data&lt;&lt;&quot; -&gt; &quot;;
        temp = temp-&gt;next;

    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2213468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2213468</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 20 May 2012 16:02:42 GMT</pubDate></item></channel></rss>