<?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[Random Access Iterator [solved]]]></title><description><![CDATA[<p>Ich hab für meine Matrix-Klasse einen RandomAccessIterator geschreiben: Beim Kompilieren bekomme ich aber Fehler (wenn ich z.B. std::sort aufrufe). Was hab ich falsch gemacht? Lasse ich den sort-Aufruf weg, kompiliert mein Programm.</p>
<p>Hier sind jeweils Ausschnitte aus meinem Code. Ich hoffe ihr könnt den Fehler finden.</p>
<p>LinearAlgebra.cpp</p>
<pre><code class="language-cpp">int main() {
	Matrix&lt;int&gt; m = useful::randomIntMatrix(4,4, -100, 100);
	sort(m.begin(), m.end());
	cout &lt;&lt; m;
}
</code></pre>
<p>matrix.h</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class Matrix {
public:
		class matrix_iterator;
		friend class matrix_iterator;
		class matrix_iterator : public std::iterator&lt;std::random_access_iterator_tag, T&gt; {
			Matrix&lt;T&gt; *m;
			int i, j;
		public:
			typedef std::random_access_iterator_tag it_cat;
			typedef typename std::iterator&lt;it_cat, T&gt;::value_type value_type;
			typedef typename std::iterator&lt;it_cat, T&gt;::difference_type diff_type;
			typedef typename std::iterator&lt;it_cat, T&gt;::reference reference;
			typedef typename std::iterator&lt;it_cat, T&gt;::pointer pointer;

			matrix_iterator(Matrix&lt;T&gt;&amp; mat, bool end = false);
			matrix_iterator();
			matrix_iterator(const matrix_iterator&amp;);
			matrix_iterator&amp; operator=(const matrix_iterator&amp;);

			matrix_iterator&amp; operator++();
			matrix_iterator&amp; operator--();
			matrix_iterator operator++(int);
			matrix_iterator operator--(int);
			matrix_iterator&amp; operator+=(diff_type);
			matrix_iterator&amp; operator-=(diff_type);
			matrix_iterator operator+(diff_type) const;
			matrix_iterator operator-(diff_type) const;

			matrix_iterator operator+(const matrix_iterator&amp;) const;
			matrix_iterator operator-(const matrix_iterator&amp;) const;

			reference operator*() const;
			pointer operator-&gt;() const;
			reference operator[](diff_type) const;

			bool operator==(const matrix_iterator&amp; it) const;
			bool operator!=(const matrix_iterator&amp; it) const;
			bool operator&lt;(const matrix_iterator&amp; it) const;
			bool operator&gt;(const matrix_iterator&amp; it) const;
			bool operator&lt;=(const matrix_iterator&amp; it) const;
			bool operator&gt;=(const matrix_iterator&amp; it) const;
		};
		matrix_iterator begin();
		matrix_iterator end();
</code></pre>
<p>Falls auch die Implementierungen relevant sind:</p>
<pre><code class="language-cpp">template &lt;class T&gt;
Matrix&lt;T&gt;::matrix_iterator::matrix_iterator(Matrix&lt;T&gt;&amp; mat, bool end) {
	m = &amp;mat;
	if (end) {
		i = mat.dim1_;
		j = 0;
	} else {
		i = 0;
		j = 0;
	}
}

template &lt;class T&gt;
Matrix&lt;T&gt;::matrix_iterator::matrix_iterator() {
	m = NULL;
	i = 0;
	j = 0;
}

template &lt;class T&gt;
Matrix&lt;T&gt;::matrix_iterator::matrix_iterator(const matrix_iterator&amp; it) {
	m = it.m;
	i = it.i;
	j = it.j;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator=(const matrix_iterator&amp; it) {
	m = it.m;
	i = it.i;
	j = it.j;
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator++() {
	j++;
	if (j &gt;= m-&gt;dim2_) {
		j = 0;
		i++;
	}
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator--() {
	j--;
	if (j &lt; 0) {
		j = m-&gt;dim2_ - 1;
		i--;
	}
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator++(int) {
	matrix_iterator it(*this);
	j++;
	if (j &gt;= m-&gt;dim2_) {
		j = 0;
		i++;
	}
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator--(int) {
	matrix_iterator it(*this);
	j--;
	if (j &lt; 0) {
		j = m-&gt;dim2_ - 1;
		i--;
	}
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator+=(diff_type x) {
	int d = m-&gt;dim2_;
	long long t = i * d + j + x;
	i = t / d;
	j = t % d;
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator-=(diff_type x) {
	int d = m-&gt;dim2_;
	long long t = i * d + j - x;
	i = t / d;
	j = t % d;
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator+(diff_type x) const {
	matrix_iterator it;
	it.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j + x;
	it.i = t / d;
	it.j = t % d;
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator-(diff_type x) const {
	matrix_iterator it;
	it.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j - x;
	it.i = t / d;
	it.j = t % d;
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator+(const matrix_iterator&amp; it) const {
	matrix_iterator erg;
	erg.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j + it.i * it.m-&gt;dim2_ + it.j;
	erg.i = t / d;
	erg.j = t % d;
	return erg;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator-(const matrix_iterator&amp; it) const {
	matrix_iterator erg;
	erg.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j - it.i * it.m-&gt;dim2_ - it.j;
	erg.i = t / d;
	erg.j = t % d;
	return erg;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator::reference Matrix&lt;T&gt;::matrix_iterator::operator*() const {
	return (*m)(i,j);
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator::pointer Matrix&lt;T&gt;::matrix_iterator::operator-&gt;() const {
	return &amp;((*m)(i,j));
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator::reference Matrix&lt;T&gt;::matrix_iterator::operator[](diff_type x) const {
	return (*m)[x];
}

template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator==(const matrix_iterator&amp; it) const {
	return i == it.i &amp;&amp; j == it.j;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator!=(const matrix_iterator&amp; it) const {
	return i != it.i || j != it.j;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&lt;(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &lt; it.j;
	else return i &lt; it.i;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&gt;(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &gt; it.j;
	else return i &gt; it.i;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&lt;=(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &lt;= it.j;
	else return i &lt;= it.i;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&gt;=(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &gt;= it.j;
	else return i &gt;= it.i;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::begin() {
	return matrix_iterator(*this);
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::end() {
	return matrix_iterator(*this, true);
}
</code></pre>
<p>Hier die ersten Zeilen der Ausgabe des Compilers...</p>
<pre><code>In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h: In Instanziierung von »void std::sort(_RAIter, _RAIter) [with _RAIter = std::iterator&lt;std::random_access_iterator_tag, int&gt;]«:
..\src\LinearAlgebra.cpp:197:14:   von hier erfordert
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Fehler: keine Übereinstimmung für »operator!=« in »__first != __last«
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung: Kandidaten sind:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/iosfwd:42:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:39,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/postypes.h:223:5: Anmerkung: template&lt;class _StateT&gt; bool std::operator!=(const std::fpos&lt;_StateT&gt;&amp;, const std::fpos&lt;_StateT&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/postypes.h:223:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::fpos&lt;_StateT&gt;« abgeleitet
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algobase.h:65:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/char_traits.h:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_pair.h:225:5: Anmerkung: template&lt;class _T1, class _T2&gt; constexpr bool std::operator!=(const std::pair&lt;_T1, _T2&gt;&amp;, const std::pair&lt;_T1, _T2&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_pair.h:225:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::pair&lt;_T1, _T2&gt;« abgeleitet
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algobase.h:68:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/char_traits.h:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:305:5: Anmerkung: template&lt;class _Iterator&gt; bool std::operator!=(const std::reverse_iterator&lt;_Iterator&gt;&amp;, const std::reverse_iterator&lt;_Iterator&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:305:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::reverse_iterator&lt;_Iterator&gt;« abgeleitet
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algobase.h:68:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/char_traits.h:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:355:5: Anmerkung: template&lt;class _IteratorL, class _IteratorR&gt; bool std::operator!=(const std::reverse_iterator&lt;_IteratorL&gt;&amp;, const std::reverse_iterator&lt;_IteratorR&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:355:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::reverse_iterator&lt;_IteratorL&gt;« abgeleitet
</code></pre>
<p>(es ist in Wirklichkeit noch deutlich mehr)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313698/random-access-iterator-solved</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 03:55:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313698.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Feb 2013 22:32:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Random Access Iterator [solved] on Fri, 08 Feb 2013 20:38:47 GMT]]></title><description><![CDATA[<p>Ich hab für meine Matrix-Klasse einen RandomAccessIterator geschreiben: Beim Kompilieren bekomme ich aber Fehler (wenn ich z.B. std::sort aufrufe). Was hab ich falsch gemacht? Lasse ich den sort-Aufruf weg, kompiliert mein Programm.</p>
<p>Hier sind jeweils Ausschnitte aus meinem Code. Ich hoffe ihr könnt den Fehler finden.</p>
<p>LinearAlgebra.cpp</p>
<pre><code class="language-cpp">int main() {
	Matrix&lt;int&gt; m = useful::randomIntMatrix(4,4, -100, 100);
	sort(m.begin(), m.end());
	cout &lt;&lt; m;
}
</code></pre>
<p>matrix.h</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class Matrix {
public:
		class matrix_iterator;
		friend class matrix_iterator;
		class matrix_iterator : public std::iterator&lt;std::random_access_iterator_tag, T&gt; {
			Matrix&lt;T&gt; *m;
			int i, j;
		public:
			typedef std::random_access_iterator_tag it_cat;
			typedef typename std::iterator&lt;it_cat, T&gt;::value_type value_type;
			typedef typename std::iterator&lt;it_cat, T&gt;::difference_type diff_type;
			typedef typename std::iterator&lt;it_cat, T&gt;::reference reference;
			typedef typename std::iterator&lt;it_cat, T&gt;::pointer pointer;

			matrix_iterator(Matrix&lt;T&gt;&amp; mat, bool end = false);
			matrix_iterator();
			matrix_iterator(const matrix_iterator&amp;);
			matrix_iterator&amp; operator=(const matrix_iterator&amp;);

			matrix_iterator&amp; operator++();
			matrix_iterator&amp; operator--();
			matrix_iterator operator++(int);
			matrix_iterator operator--(int);
			matrix_iterator&amp; operator+=(diff_type);
			matrix_iterator&amp; operator-=(diff_type);
			matrix_iterator operator+(diff_type) const;
			matrix_iterator operator-(diff_type) const;

			matrix_iterator operator+(const matrix_iterator&amp;) const;
			matrix_iterator operator-(const matrix_iterator&amp;) const;

			reference operator*() const;
			pointer operator-&gt;() const;
			reference operator[](diff_type) const;

			bool operator==(const matrix_iterator&amp; it) const;
			bool operator!=(const matrix_iterator&amp; it) const;
			bool operator&lt;(const matrix_iterator&amp; it) const;
			bool operator&gt;(const matrix_iterator&amp; it) const;
			bool operator&lt;=(const matrix_iterator&amp; it) const;
			bool operator&gt;=(const matrix_iterator&amp; it) const;
		};
		matrix_iterator begin();
		matrix_iterator end();
</code></pre>
<p>Falls auch die Implementierungen relevant sind:</p>
<pre><code class="language-cpp">template &lt;class T&gt;
Matrix&lt;T&gt;::matrix_iterator::matrix_iterator(Matrix&lt;T&gt;&amp; mat, bool end) {
	m = &amp;mat;
	if (end) {
		i = mat.dim1_;
		j = 0;
	} else {
		i = 0;
		j = 0;
	}
}

template &lt;class T&gt;
Matrix&lt;T&gt;::matrix_iterator::matrix_iterator() {
	m = NULL;
	i = 0;
	j = 0;
}

template &lt;class T&gt;
Matrix&lt;T&gt;::matrix_iterator::matrix_iterator(const matrix_iterator&amp; it) {
	m = it.m;
	i = it.i;
	j = it.j;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator=(const matrix_iterator&amp; it) {
	m = it.m;
	i = it.i;
	j = it.j;
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator++() {
	j++;
	if (j &gt;= m-&gt;dim2_) {
		j = 0;
		i++;
	}
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator--() {
	j--;
	if (j &lt; 0) {
		j = m-&gt;dim2_ - 1;
		i--;
	}
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator++(int) {
	matrix_iterator it(*this);
	j++;
	if (j &gt;= m-&gt;dim2_) {
		j = 0;
		i++;
	}
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator--(int) {
	matrix_iterator it(*this);
	j--;
	if (j &lt; 0) {
		j = m-&gt;dim2_ - 1;
		i--;
	}
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator+=(diff_type x) {
	int d = m-&gt;dim2_;
	long long t = i * d + j + x;
	i = t / d;
	j = t % d;
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator&amp; Matrix&lt;T&gt;::matrix_iterator::operator-=(diff_type x) {
	int d = m-&gt;dim2_;
	long long t = i * d + j - x;
	i = t / d;
	j = t % d;
	return *this;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator+(diff_type x) const {
	matrix_iterator it;
	it.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j + x;
	it.i = t / d;
	it.j = t % d;
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator-(diff_type x) const {
	matrix_iterator it;
	it.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j - x;
	it.i = t / d;
	it.j = t % d;
	return it;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator+(const matrix_iterator&amp; it) const {
	matrix_iterator erg;
	erg.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j + it.i * it.m-&gt;dim2_ + it.j;
	erg.i = t / d;
	erg.j = t % d;
	return erg;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::matrix_iterator::operator-(const matrix_iterator&amp; it) const {
	matrix_iterator erg;
	erg.m = m;
	int d = m-&gt;dim2_;
	long long t = i * d + j - it.i * it.m-&gt;dim2_ - it.j;
	erg.i = t / d;
	erg.j = t % d;
	return erg;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator::reference Matrix&lt;T&gt;::matrix_iterator::operator*() const {
	return (*m)(i,j);
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator::pointer Matrix&lt;T&gt;::matrix_iterator::operator-&gt;() const {
	return &amp;((*m)(i,j));
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator::reference Matrix&lt;T&gt;::matrix_iterator::operator[](diff_type x) const {
	return (*m)[x];
}

template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator==(const matrix_iterator&amp; it) const {
	return i == it.i &amp;&amp; j == it.j;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator!=(const matrix_iterator&amp; it) const {
	return i != it.i || j != it.j;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&lt;(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &lt; it.j;
	else return i &lt; it.i;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&gt;(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &gt; it.j;
	else return i &gt; it.i;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&lt;=(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &lt;= it.j;
	else return i &lt;= it.i;
}
template &lt;class T&gt;
bool Matrix&lt;T&gt;::matrix_iterator::operator&gt;=(const matrix_iterator&amp; it) const {
	if (i == it.i) return j &gt;= it.j;
	else return i &gt;= it.i;
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::begin() {
	return matrix_iterator(*this);
}

template &lt;class T&gt;
typename Matrix&lt;T&gt;::matrix_iterator Matrix&lt;T&gt;::end() {
	return matrix_iterator(*this, true);
}
</code></pre>
<p>Hier die ersten Zeilen der Ausgabe des Compilers...</p>
<pre><code>In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h: In Instanziierung von »void std::sort(_RAIter, _RAIter) [with _RAIter = std::iterator&lt;std::random_access_iterator_tag, int&gt;]«:
..\src\LinearAlgebra.cpp:197:14:   von hier erfordert
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Fehler: keine Übereinstimmung für »operator!=« in »__first != __last«
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung: Kandidaten sind:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/iosfwd:42:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:39,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/postypes.h:223:5: Anmerkung: template&lt;class _StateT&gt; bool std::operator!=(const std::fpos&lt;_StateT&gt;&amp;, const std::fpos&lt;_StateT&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/postypes.h:223:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::fpos&lt;_StateT&gt;« abgeleitet
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algobase.h:65:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/char_traits.h:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_pair.h:225:5: Anmerkung: template&lt;class _T1, class _T2&gt; constexpr bool std::operator!=(const std::pair&lt;_T1, _T2&gt;&amp;, const std::pair&lt;_T1, _T2&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_pair.h:225:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::pair&lt;_T1, _T2&gt;« abgeleitet
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algobase.h:68:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/char_traits.h:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:305:5: Anmerkung: template&lt;class _Iterator&gt; bool std::operator!=(const std::reverse_iterator&lt;_Iterator&gt;&amp;, const std::reverse_iterator&lt;_Iterator&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:305:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::reverse_iterator&lt;_Iterator&gt;« abgeleitet
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algobase.h:68:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/char_traits.h:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/ios:41,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/istream:40,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/fstream:40,
                 from ..\src\Useful.h:16,
                 from ..\src\BayRegFunc.h:75,
                 from ..\src\matrix.h:14,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:355:5: Anmerkung: template&lt;class _IteratorL, class _IteratorR&gt; bool std::operator!=(const std::reverse_iterator&lt;_IteratorL&gt;&amp;, const std::reverse_iterator&lt;_IteratorR&gt;&amp;)
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_iterator.h:355:5: Anmerkung:   Herleitung/Ersetzung von Templateargument gescheitert:
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/algorithm:63:0,
                 from ..\src\../include/cpplapack.h:18,
                 from ..\src\matrix.h:18,
                 from ..\src\RandomMatrix.h:14,
                 from ..\src\BCH.h:11,
                 from ..\src\LinearAlgebra.cpp:6:
c:\mingw\bin\../lib/gcc/mingw32/4.7.0/include/c++/bits/stl_algo.h:5431:7: Anmerkung:  »std::iterator&lt;std::random_access_iterator_tag, int&gt;« ist nicht vom Typ »const std::reverse_iterator&lt;_IteratorL&gt;« abgeleitet
</code></pre>
<p>(es ist in Wirklichkeit noch deutlich mehr)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296968</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296968</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Fri, 08 Feb 2013 20:38:47 GMT</pubDate></item><item><title><![CDATA[Reply to Random Access Iterator [solved] on Thu, 07 Feb 2013 23:14:32 GMT]]></title><description><![CDATA[<p>Ich sehe nicht den entsprechenden STL-Header:</p>
<pre><code>#include &lt;algorithm&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2296973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296973</guid><dc:creator><![CDATA[wusu]]></dc:creator><pubDate>Thu, 07 Feb 2013 23:14:32 GMT</pubDate></item><item><title><![CDATA[Reply to Random Access Iterator [solved] on Fri, 08 Feb 2013 01:43:54 GMT]]></title><description><![CDATA[<blockquote>
<p>In Instanziierung von »void std::sort(_RAIter, _RAIter) [with _RAIter = std::iterator&lt;std::random_access_iterator_tag, int&gt;]«:</p>
</blockquote>
<p>Das ist unerwartet: deinem Code zufolge sollte der deduzierte Typ Matrix&lt;int&gt;::matrix_iterator sein.<br />
Bist du sicher, das der gepostete Code tatsächlich mit dem fehlerhaften übereinstimmt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2296977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2296977</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 08 Feb 2013 01:43:54 GMT</pubDate></item><item><title><![CDATA[Reply to Random Access Iterator [solved] on Fri, 08 Feb 2013 10:26:18 GMT]]></title><description><![CDATA[<p>algorithm wird inkludiert (auch in der matrix.h, falls das nötig sein sollte).</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@Camper</a>:<br />
Ja, den fehlerhaften Code hab ich kopiert und hier gepostet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297043</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Fri, 08 Feb 2013 10:26:18 GMT</pubDate></item><item><title><![CDATA[Reply to Random Access Iterator [solved] on Fri, 08 Feb 2013 19:15:53 GMT]]></title><description><![CDATA[<p>*push*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297261</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297261</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Fri, 08 Feb 2013 19:15:53 GMT</pubDate></item><item><title><![CDATA[Reply to Random Access Iterator [solved] on Fri, 08 Feb 2013 19:44:42 GMT]]></title><description><![CDATA[<p>Ramanujan schrieb:</p>
<blockquote>
<p>*push*</p>
</blockquote>
<p>Minimalen aber vollständigen (in Hinblick auf den Fehler) Code bitte, damit wir das nachvollziehen können.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297269</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 08 Feb 2013 19:44:42 GMT</pubDate></item><item><title><![CDATA[Reply to Random Access Iterator [solved] on Fri, 08 Feb 2013 20:38:31 GMT]]></title><description><![CDATA[<p>Ich hab den Fehler nun selbst gefunden:</p>
<p>operator+(const matrix_iterator&amp;) const;<br />
operator-(const matrix_iterator&amp;) const;</p>
<p>müssen jeweils diff_type zurückgeben und keinen matrix_iterator. Das Problem ist, dass das erstmal nicht zu einem Fehler führt, sondern erst, wenn im std::sort-Algorithmus auf der Differenz aus begin- und end-Iterator der operator&gt;&gt;= aufgerufen wird. Daher kamen diese recht merkwürdigen Fehler.</p>
<p>Ich hab aber noch eine Frage: Der Rückgabewert von operator- ist klar. Aber bei operator+? Wenn ich das auf Pointer übertrage: Was hat es für einen Sinn, zwei Pointer zu addieren? Da landet man doch irgendwo im Niergendwo im Speicher.</p>
<p>Edit: Ok, von dem operator+ der zwei Iteratoren bekommt steht nichts bei cpp-reference. Da war meine Vorlage für den RandomAccessIterator einfach falsch. (mit dem falschen Rückgabetyp hatte ich aber selbst falsch abgeschrieben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297273</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Fri, 08 Feb 2013 20:38:31 GMT</pubDate></item></channel></rss>