<?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[Template Klasse]]></title><description><![CDATA[<pre><code>#ifndef MEINSTACK_H
#define MEINSTACK_H
#include &lt;cassert&gt;
#include &lt;vector&gt;
using namespace std;
// Template Klasse
template&lt;typename T, unsigned int MaximalWert&gt;
class SimpleStack{
public:
	bool emtpy() const { return anzahl == 0; }
	void clear() { anzahl = 0; }
	void hinzufuegen(const T&amp; );
	void entfernen();
	const T&amp; top() const;
	int getMAX() const { return max; }
	int getBelegteAnzahl() const { return anzahl; }
private:
	unsigned int anzahl{ 0 };
	vector&lt;T&gt; StackArray(MaximalWert);
};
// Typdefintionen SimpleStack
template&lt;typename T, unsigned int m&gt;
void SimpleStack&lt;T, m&gt;::hinzufuegen(const T&amp; c){
	StackArray.at([anzahl++]) = c;
}
template&lt;typename T, unsigned int m&gt;
void SimpleStack&lt;T, m&gt;::entfernen(){
	assert(!empty());
	--anzahl;
}
// Letztes Element des Arrays lesen
template&lt;typename T, unsigned int m&gt;
const T&amp; SimpleStack&lt;T, m&gt;::top()const {
	return StackArray[anzahl-1];
}

#endif
</code></pre>
<p>Fehler:<br />
Fehler 1 error C2061: Syntaxfehler: Bezeichner 'MaximalWert' c:\users\programmieren\documents\visual studio 2013\projects\projekt2\projekt2\meinstack.h 19 1 Projekt2</p>
<p>Ich sehe den Fehler nicht könnt ihr mir vllt. weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327840/template-klasse</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 16:45:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327840.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Sep 2014 14:40:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template Klasse on Sun, 07 Sep 2014 14:40:08 GMT]]></title><description><![CDATA[<pre><code>#ifndef MEINSTACK_H
#define MEINSTACK_H
#include &lt;cassert&gt;
#include &lt;vector&gt;
using namespace std;
// Template Klasse
template&lt;typename T, unsigned int MaximalWert&gt;
class SimpleStack{
public:
	bool emtpy() const { return anzahl == 0; }
	void clear() { anzahl = 0; }
	void hinzufuegen(const T&amp; );
	void entfernen();
	const T&amp; top() const;
	int getMAX() const { return max; }
	int getBelegteAnzahl() const { return anzahl; }
private:
	unsigned int anzahl{ 0 };
	vector&lt;T&gt; StackArray(MaximalWert);
};
// Typdefintionen SimpleStack
template&lt;typename T, unsigned int m&gt;
void SimpleStack&lt;T, m&gt;::hinzufuegen(const T&amp; c){
	StackArray.at([anzahl++]) = c;
}
template&lt;typename T, unsigned int m&gt;
void SimpleStack&lt;T, m&gt;::entfernen(){
	assert(!empty());
	--anzahl;
}
// Letztes Element des Arrays lesen
template&lt;typename T, unsigned int m&gt;
const T&amp; SimpleStack&lt;T, m&gt;::top()const {
	return StackArray[anzahl-1];
}

#endif
</code></pre>
<p>Fehler:<br />
Fehler 1 error C2061: Syntaxfehler: Bezeichner 'MaximalWert' c:\users\programmieren\documents\visual studio 2013\projects\projekt2\projekt2\meinstack.h 19 1 Projekt2</p>
<p>Ich sehe den Fehler nicht könnt ihr mir vllt. weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2416452</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416452</guid><dc:creator><![CDATA[Aoki_san]]></dc:creator><pubDate>Sun, 07 Sep 2014 14:40:08 GMT</pubDate></item><item><title><![CDATA[Reply to Template Klasse on Sun, 07 Sep 2014 15:27:53 GMT]]></title><description><![CDATA[<p>Du musst die Werte im Konstruktor initialisieren:</p>
<pre><code>SimpleStack()   : anzahl(0), StackArray(MaximalWert) {}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2416456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416456</guid><dc:creator><![CDATA[error12]]></dc:creator><pubDate>Sun, 07 Sep 2014 15:27:53 GMT</pubDate></item><item><title><![CDATA[Reply to Template Klasse on Sun, 07 Sep 2014 15:41:26 GMT]]></title><description><![CDATA[<p>Beispiel:<br />
SimpleStack&lt;int, 67&gt; Stack1;</p>
<p>So würde ich ein Objekt erzeugen dabei wird der default konstruktor aufgerufen<br />
In der Klasse habe ich anzahl mit 0 initalisiert (sobald ein objekt erzeugt wird werden die werte ja zugewiesen)<br />
und 67 wird da doch eigentlich dem vector automatisch zugewiesen oder nicht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Ich habs auch schon mit dem Konstruktor versucht der Fehler bleibt trotzdem erhalten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2416458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416458</guid><dc:creator><![CDATA[Aoki_san]]></dc:creator><pubDate>Sun, 07 Sep 2014 15:41:26 GMT</pubDate></item><item><title><![CDATA[Reply to Template Klasse on Sun, 07 Sep 2014 17:31:40 GMT]]></title><description><![CDATA[<pre><code>StackArray.at([anzahl++]) = c;
</code></pre>
<p>Soll das wirklich ein Lambdaausdruck sein?</p>
<pre><code>unsigned int anzahl{ 0 };
vector&lt;T&gt; StackArray (MaximalWert);
</code></pre>
<p>Was ist an diesen beiden Zeilen unterschiedlich, was dafür sorgen könnte, dass das eine richtig und das andere falsch ist? Bonusfrage: Was interpretiert der Compiler in die zweite Zeile hinein?<br />
Wichtige Zusatzfrage zu eventuellen Korrekturen: Mit welcher Syntax wird welcher Konstruktor des vectors aufgerufen?</p>
<pre><code>assert(!empty());
</code></pre>
<p>Hier wird es auch zu Problemen kommen, da aufgrund der arkanen Regeln von Templates nicht klar ist, um welches empty es sich handelt. Du musst explizit sagen, dass es um das empty deiner Klasse geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2416468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416468</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 07 Sep 2014 17:31:40 GMT</pubDate></item><item><title><![CDATA[Reply to Template Klasse on Mon, 08 Sep 2014 11:13:52 GMT]]></title><description><![CDATA[<p>ich antworte darauf sobald ich es raushabe <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 />
du kannst mich ja dann gerne erneut korrigieren falls es falsch sein sollte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2416514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416514</guid><dc:creator><![CDATA[Aoki_san]]></dc:creator><pubDate>Mon, 08 Sep 2014 11:13:52 GMT</pubDate></item><item><title><![CDATA[Reply to Template Klasse on Thu, 11 Sep 2014 04:03:59 GMT]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;

template&lt;typename T, unsigned int MaximalWert&gt; 
class SimpleStack{ 
public:
    SimpleStack&lt;T,MaximalWert&gt;() {
    anzahl = 0;
    vector&lt;T&gt;Stackarray(MaximalWert);
} 
    bool empty() const { return anzahl == 0; } 
    void clear() { anzahl = 0; } 
    void hinzufuegen(const T&amp; ); 
    void entfernen(); 
    const T&amp; top() const; 
    int getMAX() const { return max; } 
    int getBelegteAnzahl() const { return anzahl; } 
private: 
    unsigned int anzahl; 
    vector&lt;T&gt; StackArray; 
}; 
// Typdefintionen SimpleStack 
template&lt;typename T, unsigned int m&gt; 
void SimpleStack&lt;T, m&gt;::hinzufuegen(const T&amp; c){ 
    StackArray.at(anzahl++) = c; 
} 
template&lt;typename T, unsigned int m&gt; 
void SimpleStack&lt;T, m&gt;::entfernen(){ 
    assert(!empty()); 
    --anzahl; 
} 
// Letztes Element des Arrays lesen 
template&lt;typename T, unsigned int m&gt; 
const T&amp; SimpleStack&lt;T, m&gt;::top()const { 
    return StackArray[anzahl-1]; 
} 
int main() {
	// your code goes here
	return 0;
}
</code></pre>
<p>Habs voll vergessen sorry.</p>
<p>Kann ich meinen Code irgendwie noch verbessern?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2416967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416967</guid><dc:creator><![CDATA[Aoki_s]]></dc:creator><pubDate>Thu, 11 Sep 2014 04:03:59 GMT</pubDate></item><item><title><![CDATA[Reply to Template Klasse on Thu, 11 Sep 2014 04:51:18 GMT]]></title><description><![CDATA[<p>Aoki_s schrieb:</p>
<blockquote>
<p>Kann ich meinen Code irgendwie noch verbessern?</p>
</blockquote>
<p>Was heißt hier verbessern? Der ist schlicht falsch, da du wieder mal &quot;Programmieren durch Ausprobieren&quot; praktiziert hast. So lange zufällig Zeichen einfügen bis etwas compiliert, hat mit Programmieren nix zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2416970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2416970</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 11 Sep 2014 04:51:18 GMT</pubDate></item></channel></rss>