<?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[Templates und Konstruktoren...unverständlich??]]></title><description><![CDATA[<p>Hallo Zusammen</p>
<p>Ich habe folgenden Quelltext:</p>
<p>0203.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main() {
	CircularBuffer&lt;int&gt; a();                      (error: expected primary-expression before &quot;template&quot;     error: expected `;' before &quot;template&quot;)  

	for(int i=0;i&lt;15;i++) {
		a.add(i);                            (error: `a' was not declared in this scope)       
	}
	return 0;
}
</code></pre>
<p>0203.cpp.h</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using std::cout;
using std::endl;

template &lt;typename T&gt;
CircularBuffer&lt;T&gt;::CircularBuffer() {                                
	next = index;
	for(int i=0;i&lt;20;i++) {
			A[i] = 0;
		}
}

template &lt;typename T&gt;
void CircularBuffer&lt;T&gt;::add(T&amp; value) {                            
	int i=0;
		while(i&lt;20) {
			if(A[i]==&quot; &quot;)
				A[i]=value;
			else
				i++;
		}
		if(i==20)
			A[0]=value;
}

template &lt;typename T&gt;
void CircularBuffer&lt;T&gt;::find(T&amp; value) {                           
	int i=0;
	while(i&lt;20&amp;&amp;A[i]!=value)
		i++;
	if(A[i]==value)
		cout &lt;&lt; &quot;An der Stelle &quot; &lt;&lt; i &lt;&lt; &quot; ist der Wert &quot; &lt;&lt; value &lt;&lt; &quot; vorhanden.&quot;;
	else
		cout &lt;&lt; &quot;Der Wert &quot; &lt;&lt; value &lt;&lt; &quot; ist im Buffer nicht enthalten.&quot;;
}

template &lt;typename T&gt;
void CircularBuffer&lt;T&gt;::print() {                              
	cout &lt;&lt; &quot;Die Werte im Buffer betragen: &quot;;
	for(int i=0;i&lt;20;i++) {
		cout &lt;&lt; A[i];
	}
}
</code></pre>
<p>0203.h</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;0203.cpp.h&quot;

template &lt;typename T&gt;
class CircularBuffer {
	public:
		CircularBuffer();
		void add(T value);
		void find(T value);
		void print();
		T A[20];
	private:
		int next;
};
</code></pre>
<pre><code>**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\0203.o ..\src\0203.cpp
..\src\0203.cpp: In function `int main()':
..\src\0203.cpp:12: error: expected primary-expression before &quot;template&quot;
..\src\0203.cpp:12: error: expected `;' before &quot;template&quot;
..\src\0203.cpp:16: error: `a' was not declared in this scope
..\src\0203.cpp:16: warning: unused variable 'a'
Build error occurred, build is stopped
Time consumed: 1875  ms.
</code></pre>
<p>Warum ist a nicht declared?? ich deklariere a doch... Ist der Compiler noch bei Sinnen...???</p>
<p>lg<br />
joethe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/235742/templates-und-konstruktoren-unverständlich</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 04:07:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/235742.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Mar 2009 22:28:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Templates und Konstruktoren...unverständlich?? on Thu, 05 Mar 2009 22:37:04 GMT]]></title><description><![CDATA[<p>Hallo Zusammen</p>
<p>Ich habe folgenden Quelltext:</p>
<p>0203.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main() {
	CircularBuffer&lt;int&gt; a();                      (error: expected primary-expression before &quot;template&quot;     error: expected `;' before &quot;template&quot;)  

	for(int i=0;i&lt;15;i++) {
		a.add(i);                            (error: `a' was not declared in this scope)       
	}
	return 0;
}
</code></pre>
<p>0203.cpp.h</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using std::cout;
using std::endl;

template &lt;typename T&gt;
CircularBuffer&lt;T&gt;::CircularBuffer() {                                
	next = index;
	for(int i=0;i&lt;20;i++) {
			A[i] = 0;
		}
}

template &lt;typename T&gt;
void CircularBuffer&lt;T&gt;::add(T&amp; value) {                            
	int i=0;
		while(i&lt;20) {
			if(A[i]==&quot; &quot;)
				A[i]=value;
			else
				i++;
		}
		if(i==20)
			A[0]=value;
}

template &lt;typename T&gt;
void CircularBuffer&lt;T&gt;::find(T&amp; value) {                           
	int i=0;
	while(i&lt;20&amp;&amp;A[i]!=value)
		i++;
	if(A[i]==value)
		cout &lt;&lt; &quot;An der Stelle &quot; &lt;&lt; i &lt;&lt; &quot; ist der Wert &quot; &lt;&lt; value &lt;&lt; &quot; vorhanden.&quot;;
	else
		cout &lt;&lt; &quot;Der Wert &quot; &lt;&lt; value &lt;&lt; &quot; ist im Buffer nicht enthalten.&quot;;
}

template &lt;typename T&gt;
void CircularBuffer&lt;T&gt;::print() {                              
	cout &lt;&lt; &quot;Die Werte im Buffer betragen: &quot;;
	for(int i=0;i&lt;20;i++) {
		cout &lt;&lt; A[i];
	}
}
</code></pre>
<p>0203.h</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;0203.cpp.h&quot;

template &lt;typename T&gt;
class CircularBuffer {
	public:
		CircularBuffer();
		void add(T value);
		void find(T value);
		void print();
		T A[20];
	private:
		int next;
};
</code></pre>
<pre><code>**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\0203.o ..\src\0203.cpp
..\src\0203.cpp: In function `int main()':
..\src\0203.cpp:12: error: expected primary-expression before &quot;template&quot;
..\src\0203.cpp:12: error: expected `;' before &quot;template&quot;
..\src\0203.cpp:16: error: `a' was not declared in this scope
..\src\0203.cpp:16: warning: unused variable 'a'
Build error occurred, build is stopped
Time consumed: 1875  ms.
</code></pre>
<p>Warum ist a nicht declared?? ich deklariere a doch... Ist der Compiler noch bei Sinnen...???</p>
<p>lg<br />
joethe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1674974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1674974</guid><dc:creator><![CDATA[joethe]]></dc:creator><pubDate>Thu, 05 Mar 2009 22:37:04 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Konstruktoren...unverständlich?? on Thu, 05 Mar 2009 22:40:15 GMT]]></title><description><![CDATA[<p>Kennst du diesen Spruch:<br />
&quot;Das Problem sitzt meistens nicht im Computer, sondern davor!&quot;<br />
Tja, gilt natürlich auch für deinen Fall! <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="😉"
    /><br />
Das ist natürlich bestimmt nicht das was du machen willst:</p>
<pre><code class="language-cpp">CircularBuffer&lt;int&gt; a();
</code></pre>
<p>Sieht doch eigentlich fast so aus, oder:</p>
<pre><code class="language-cpp">int foo();
</code></pre>
<p>Hem...<br />
Du wolltest wohl eher das machen:</p>
<pre><code class="language-cpp">CircularBuffer&lt;int&gt; a;
</code></pre>
<p>Man lässt die Klammern weg, wenn man den Default-Ctor benutzen will.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1674977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1674977</guid><dc:creator><![CDATA[Bulli]]></dc:creator><pubDate>Thu, 05 Mar 2009 22:40:15 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Konstruktoren...unverständlich?? on Thu, 05 Mar 2009 22:41:47 GMT]]></title><description><![CDATA[<p>Du machst ja auch nicht das:</p>
<pre><code class="language-cpp">int i();
</code></pre>
<p>Sondern eher das:</p>
<pre><code class="language-cpp">int i;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1674978</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1674978</guid><dc:creator><![CDATA[Bulli]]></dc:creator><pubDate>Thu, 05 Mar 2009 22:41:47 GMT</pubDate></item><item><title><![CDATA[Reply to Templates und Konstruktoren...unverständlich?? on Fri, 06 Mar 2009 06:50:47 GMT]]></title><description><![CDATA[<p>Ausserdem, woher soll er CircularBuffer kennen? In &lt;iostream&gt; ist der sicher nicht enthalten.</p>
<p>Also echt, dem armen Compiler immer gleich etwas unterstellen zu wollen, fürchterlich. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1675020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1675020</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 06 Mar 2009 06:50:47 GMT</pubDate></item></channel></rss>