<?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[&amp;lt;&amp;lt; - Operator überschreiben]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich bekomme einen Compile-Fehler (Zeile 70) und kann nicht verstehen was da falsch ist. Könnte bitte jemand Helfen?</p>
<p>Danke schon mal.</p>
<pre><code class="language-cpp">#ifndef __STACK_INCLUDED__
#define __STACK_INCLUDED__

#include &lt;iostream&gt;
#include &lt;list&gt;
#include &quot;EmptyStackException.h&quot;

template&lt;class T&gt;
/**
 * Implementiert einen Stack mit Hilfe der generischen
 * STL-Klasse &lt;code&gt;list&lt;/code&gt;.
 */
class Stack {

private:
	/**
	 * enthaelt die Elemente.
	 */
	std::list&lt;T&gt; stack;

public:

	/**
	 * Prueft ob Stack leer ist oder nicht
	 * @return 1 wenn Stack leer ist.
	 **/
	bool empty() {
		return stack.empty();
	}

	/**
	 * Gibt das oberste Stack element als Referenz zurueck.
	 * @return referenz auf das oberste Element.
	 **/
	T&amp; peek() {
		//wenn stack nicht leer ist
		if (!stack.empty()) {
			return stack.back();
		} else {
			throw EmptyStackException();
		}
	}

	/**
	 * Entfernt das oberste Element vom Stack
	 **/
	void pop() {
		//wenn stack nicht leer ist
		if (!stack.empty()) {
			stack.pop_back();
		} else {
			throw EmptyStackException();
		}
	}

	/**
	 * legt ein neues Element auf den stack.
	 * @param value das neue Element
	 **/
	void push(T value) {
		stack.push_back(value);
	}

	/**
	 * Ueberschreibt &lt;&lt; (cout) Operator.
	 */
	friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Stack&amp; stackSrc) {
		std::list&lt;T&gt;::iterator it; // HIER FEHLER!
		for(it = stackSrc.stack.end(); it != stackSrc.stack.begin(); it--){
			std::cout &lt;&lt; *it &lt;&lt; std::endl;
		}
		return out;
	}
};
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/265838/lt-lt-operator-überschreiben</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 20:32:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/265838.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Apr 2010 16:36:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 16:36:25 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich bekomme einen Compile-Fehler (Zeile 70) und kann nicht verstehen was da falsch ist. Könnte bitte jemand Helfen?</p>
<p>Danke schon mal.</p>
<pre><code class="language-cpp">#ifndef __STACK_INCLUDED__
#define __STACK_INCLUDED__

#include &lt;iostream&gt;
#include &lt;list&gt;
#include &quot;EmptyStackException.h&quot;

template&lt;class T&gt;
/**
 * Implementiert einen Stack mit Hilfe der generischen
 * STL-Klasse &lt;code&gt;list&lt;/code&gt;.
 */
class Stack {

private:
	/**
	 * enthaelt die Elemente.
	 */
	std::list&lt;T&gt; stack;

public:

	/**
	 * Prueft ob Stack leer ist oder nicht
	 * @return 1 wenn Stack leer ist.
	 **/
	bool empty() {
		return stack.empty();
	}

	/**
	 * Gibt das oberste Stack element als Referenz zurueck.
	 * @return referenz auf das oberste Element.
	 **/
	T&amp; peek() {
		//wenn stack nicht leer ist
		if (!stack.empty()) {
			return stack.back();
		} else {
			throw EmptyStackException();
		}
	}

	/**
	 * Entfernt das oberste Element vom Stack
	 **/
	void pop() {
		//wenn stack nicht leer ist
		if (!stack.empty()) {
			stack.pop_back();
		} else {
			throw EmptyStackException();
		}
	}

	/**
	 * legt ein neues Element auf den stack.
	 * @param value das neue Element
	 **/
	void push(T value) {
		stack.push_back(value);
	}

	/**
	 * Ueberschreibt &lt;&lt; (cout) Operator.
	 */
	friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Stack&amp; stackSrc) {
		std::list&lt;T&gt;::iterator it; // HIER FEHLER!
		for(it = stackSrc.stack.end(); it != stackSrc.stack.begin(); it--){
			std::cout &lt;&lt; *it &lt;&lt; std::endl;
		}
		return out;
	}
};
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1890028</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890028</guid><dc:creator><![CDATA[Dit_]]></dc:creator><pubDate>Thu, 29 Apr 2010 16:36:25 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 16:46:28 GMT]]></title><description><![CDATA[<p>1. poste bei so was doch bitte auch immer den fehler mit</p>
<p>2. der fehler kommt nicht hier <code>std::list&lt;T&gt;::iterator it; // HIER FEHLER!</code> sondern wirklich in Zeile 70.<br />
Dazu musst du aber diese Zeile ändern, in:<br />
<code>std::list&lt;T&gt;::const_iterator it;</code><br />
du hast ein konstantes objekt - kannst also keine nicht const-funktionen aufrufen.<br />
und <code>std::list&lt;T&gt;::iterator std::list&lt;T&gt;::begin()</code> ist nun mal nicht const - <code>std::list&lt;T&gt;::const_iterator std::list&lt;T&gt;::begin() const</code> aber <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>bb</p>
<p>PS:</p>
<ol>
<li><code>__STACK_INCLUDED__</code> schlechter include name - alles mit 2 unterstrichen am stück oder unterstrich großbuchstabe am anfang ist für den compiler reserviert - ohne einschränkungen.<br />
2. es gibt bereits eine klasse std::stack ( <code>#include &lt;stack&gt;</code> ), weist du das?</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/1890033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890033</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 29 Apr 2010 16:46:28 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 19:22:41 GMT]]></title><description><![CDATA[<p>Das Thema kam erst gestern - da muss typename vor std::list&lt;T&gt;::iterator hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1890130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890130</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Thu, 29 Apr 2010 19:22:41 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 19:28:14 GMT]]></title><description><![CDATA[<p>wxSkip schrieb:</p>
<blockquote>
<p>Das Thema kam erst gestern - da muss typename vor std::list&lt;T&gt;::iterator hin.</p>
</blockquote>
<p>stimmt - das typename braucht man auch noch(zumindest normalerweise, der msvc sollte es nicht brauchen) - aber nichts destro trotz muss da nen const_iterator hin...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1890132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890132</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 29 Apr 2010 19:28:14 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 19:36:11 GMT]]></title><description><![CDATA[<p>ok</p>
<pre><code class="language-cpp">typename std::list&lt;T&gt;::const_iterator it;
</code></pre>
<p>was macht dieses typename in dem fall genau?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1890135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890135</guid><dc:creator><![CDATA[Dit_]]></dc:creator><pubDate>Thu, 29 Apr 2010 19:36:11 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 19:37:27 GMT]]></title><description><![CDATA[<p>es sagt dem compiler, dass es sich um einen typen handelt und nicht um eine (static) variable</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1890138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890138</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 29 Apr 2010 19:37:27 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;lt;&amp;lt; - Operator überschreiben on Thu, 29 Apr 2010 19:38:19 GMT]]></title><description><![CDATA[<p><a href="http://pages.cs.wisc.edu/~driscoll/typename.html" rel="nofollow">http://pages.cs.wisc.edu/~driscoll/typename.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1890139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1890139</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Thu, 29 Apr 2010 19:38:19 GMT</pubDate></item></channel></rss>