<?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 verschachteln...]]></title><description><![CDATA[<p>warumm bekomm ich einen fehler wenn ich so ein mehrdim. array machen will?</p>
<pre><code class="language-cpp">dynArray&lt;dynArray&lt;int&gt; &gt; foo;
</code></pre>
<p>KLASSE:</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void dispArray();

	void fillArray(T data);
};

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray() : index(0), zeilen(1)
{
	mainArray = new T[1];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(int size) : index(0), zeilen(size)
{
	mainArray = new T[size];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(dynArray&lt;T&gt; const &amp;ref) : zeilen(ref.zeilen), index(ref.index)
{
	for(int i = 0; i &lt; index; i++)
		mainArray[i] = ref.mainArray[i];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::~dynArray()
{
	std::cout&lt;&lt;&quot;Speicher vom Array wird jetzt wieder freigegeben&quot;&lt;&lt;std::endl;
	delete [] mainArray;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::setSize(int range)
{
	zeilen(range);
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::dispArray()
{
std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;getSize()&lt;&lt;std::endl;
std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;getIndex()&lt;&lt;std::endl;

	for(int i = 0; i &lt; index; i++)
		std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt;mainArray[i]&lt;&lt;std::endl;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::fillArray(T data)
{
	mainArray[index] = data;
	index++;

	T tempArray[index];
	for(int i = 0; i &lt; zeilen; i++)
		tempArray[i] = mainArray[i];

	if(zeilen &lt;= index)
	{
		zeilen++;
		mainArray = new int[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/130610/template-klasse-verschachteln</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 17:12:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/130610.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Dec 2005 13:17:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 13:17:41 GMT]]></title><description><![CDATA[<p>warumm bekomm ich einen fehler wenn ich so ein mehrdim. array machen will?</p>
<pre><code class="language-cpp">dynArray&lt;dynArray&lt;int&gt; &gt; foo;
</code></pre>
<p>KLASSE:</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void dispArray();

	void fillArray(T data);
};

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray() : index(0), zeilen(1)
{
	mainArray = new T[1];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(int size) : index(0), zeilen(size)
{
	mainArray = new T[size];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(dynArray&lt;T&gt; const &amp;ref) : zeilen(ref.zeilen), index(ref.index)
{
	for(int i = 0; i &lt; index; i++)
		mainArray[i] = ref.mainArray[i];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::~dynArray()
{
	std::cout&lt;&lt;&quot;Speicher vom Array wird jetzt wieder freigegeben&quot;&lt;&lt;std::endl;
	delete [] mainArray;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::setSize(int range)
{
	zeilen(range);
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::dispArray()
{
std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;getSize()&lt;&lt;std::endl;
std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;getIndex()&lt;&lt;std::endl;

	for(int i = 0; i &lt; index; i++)
		std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt;mainArray[i]&lt;&lt;std::endl;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::fillArray(T data)
{
	mainArray[index] = data;
	index++;

	T tempArray[index];
	for(int i = 0; i &lt; zeilen; i++)
		tempArray[i] = mainArray[i];

	if(zeilen &lt;= index)
	{
		zeilen++;
		mainArray = new int[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/949519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949519</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Sun, 25 Dec 2005 13:17:41 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 13:26:25 GMT]]></title><description><![CDATA[<p>Was ist denn der Fehler?</p>
<p>Btw. was haben denn die Privaten Methoden für einen Sinn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/949522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949522</guid><dc:creator><![CDATA[leo_]]></dc:creator><pubDate>Sun, 25 Dec 2005 13:26:25 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 15:02:54 GMT]]></title><description><![CDATA[<p>Die Implementation deiner Methoden muss bei Templateklassen inline geschehen, also in der selben Datei.<br />
Da ist auch gerade ein anderer Thread zu aktiv, such einfach mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/949579</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949579</guid><dc:creator><![CDATA[Headhunter]]></dc:creator><pubDate>Sun, 25 Dec 2005 15:02:54 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 16:10:30 GMT]]></title><description><![CDATA[<p>Headhunter schrieb:</p>
<blockquote>
<p>Die Implementation deiner Methoden muss bei Templateklassen inline geschehen, also in der selben Datei.<br />
Da ist auch gerade ein anderer Thread zu aktiv, such einfach mal.</p>
</blockquote>
<p>Falls du mich meinst: Das ist mir klar, ich meinte eigentlich die privaten<br />
Methoden getElement, getIndex und getSize die ja eigentlich ziemlich unnötig sind. <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/949635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949635</guid><dc:creator><![CDATA[leo_]]></dc:creator><pubDate>Sun, 25 Dec 2005 16:10:30 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 16:42:21 GMT]]></title><description><![CDATA[<p>wenn ich den erwähnten code in der main habe bekomm ich sowas:</p>
<pre><code>/home/dgdaniel/develop/cpp/dynarray/src/main.cpp:38: instantiated from here
/home/dgdaniel/develop/cpp/dynarray/src/dynarray.hpp:102: error: no match for ‘operator&lt;&lt;’ in ‘std::operator&lt;&lt; [with _Traits = std::char_traits&lt;char&gt;](((std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)(+ std::cout. std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt; [with _CharT = char, _Traits = std::char_traits&lt;char&gt;](i))), ((const char*)&quot;.) &quot;)) &lt;&lt; *(((dynArray&lt;dynArray&lt;int&gt; &gt;*)this)-&gt;dynArray&lt;dynArray&lt;int&gt; &gt;::mainArray + (+(((unsigned int)i) * 16u)))’
/usr/include/c++/4.0.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:78: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ios&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ios&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:90: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::ios_base&amp; (*)(std::ios_base&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:125: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:159: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:102: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(bool) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:177: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:188: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:192: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:203: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:183: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:218: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:242: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:218: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(float) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:265: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:288: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(const void*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:311: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_streambuf&lt;_CharT, _Traits&gt;*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:448: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, char) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:509: note: std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, char) [with _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:459: note: std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, signed char) [with _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:464: note: std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, unsigned char) [with _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:571: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, const char*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/bits/ostream.tcc:616: note: std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, const char*) [with _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:498: note: std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, const signed char*) [with _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.0.2/ostream:503: note: std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, const unsigned char*) [with _Traits = std::char_traits&lt;char&gt;]
gmake[2]: *** [main.o] Fehler 1
gmake[2]: Das Target »all« wurde wegen Fehlern nicht aktualisiert.
gmake[1]: *** [all-recursive] Fehler 1
gmake[2]: Für das Ziel »all-am« ist nichts zu tun.
gmake: *** [all] Fehler 2
*** Beendet mit Status: 2 ***
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/949646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949646</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Sun, 25 Dec 2005 16:42:21 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 16:43:59 GMT]]></title><description><![CDATA[<p>und wegen den privaten methoden... gar keinen, deshalb hab ich sie privat gemacht! sind nur für die ausgabefkt. dispArray() da.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/949648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949648</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Sun, 25 Dec 2005 16:43:59 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 16:52:45 GMT]]></title><description><![CDATA[<p>fällt dir eine andere methode ein auf private variablen, zuzugreifen ohne memberfunktionen zu benutzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/949654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949654</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Sun, 25 Dec 2005 16:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Sun, 25 Dec 2005 17:01:02 GMT]]></title><description><![CDATA[<p>Der Fehler liegt in dispArray(). Du versuchst, operator&lt;&lt;(const ostream&amp; os, const dynArray&lt;dynArray&lt;int&gt; &gt;) aufzurufen, aber das existiert eben nicht.</p>
<p>Das ist das gleiche, wie wenn du das hier machen würdest:</p>
<pre><code class="language-cpp">dynArray&lt;int&gt; array;
std::cout &lt;&lt; array;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/949662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/949662</guid><dc:creator><![CDATA[leo_]]></dc:creator><pubDate>Sun, 25 Dec 2005 17:01:02 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 10:30:53 GMT]]></title><description><![CDATA[<p>ich habe jetzt meine klasse umgebaut und diese funktion global gemacht:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
void dispArray(dynArray&lt;T&gt; array)
{
	std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;array.getSize()&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;array.getIndex()&lt;&lt;std::endl;

	for(int i = 0; i &lt; index; i++)
		std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt; array.getMainArray(i) &lt;&lt;std::endl;
}
</code></pre>
<p>klasse:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void dispArray();

	void fillArray(T data);

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}
	T getMainArray(int pos)
	{
		return mainArray[pos];
	}
};
</code></pre>
<p>nur bekomme ich jetzt</p>
<pre><code>error: ISO C++ forbids comparison between pointer and integer
</code></pre>
<p>warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950056</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 10:30:53 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 10:54:42 GMT]]></title><description><![CDATA[<p>Thread kann gelöscht werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950085</guid><dc:creator><![CDATA[Wächter]]></dc:creator><pubDate>Mon, 26 Dec 2005 10:54:42 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 11:22:55 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/26451">@dgrat</a>: Du hast nicht wirklich was verändert. Das Problem ist jetzt die folgende Funktion:</p>
<pre><code class="language-cpp">T getMainArray(int pos)
    {
        return mainArray[pos];
    }
</code></pre>
<p>Solange T = builtin ist das kein Problem, da Arrays aus Builtins den operator[] zur Verfügung stellen. Wenn T dagegen für dynArray&lt;builtin&gt; steht (also T = dynArray&lt;builtin&gt;), gibt es keinen operator[] über welchen du auf die Elemente des Arrays vom Typ dynArray&lt;builtin&gt; zugreifen kannst.</p>
<p>Lösung: Du überlädst den operator[] in der Klasse für den Typ T.</p>
<p>Btw: Elemente werden in der Reihenfolge ihrer Deklaration initialisiert! =&gt; Schau dir deine Initialisierungslisten mal näher an, diese sind nämlich 'fehlerhaft'.</p>
<p>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950107</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Mon, 26 Dec 2005 11:22:55 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 11:37:56 GMT]]></title><description><![CDATA[<p>es ist mir etwas peinlich, aber ich habe noch nie einen operator überladen!<br />
<a href="http://www.willemer.de/informatik/cpp/cppovrld.htm" rel="nofollow">http://www.willemer.de/informatik/cpp/cppovrld.htm</a><br />
ABER ein bissel ge google t</p>
<p>wie müsste iene überladene operator-fkt aussehen?</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void fillArray(T data);

	void dispArray();

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}
};

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray() : index(0), zeilen(1)
{
	mainArray = new T[1];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(int size) : index(0), zeilen(size)
{
	mainArray = new T[size];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(dynArray&lt;T&gt; const &amp;ref) : zeilen(ref.zeilen), index(ref.index)
{
	for(int i = 0; i &lt; index; i++)
		mainArray[i] = ref.mainArray[i];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::~dynArray()
{
	std::cout&lt;&lt;&quot;Speicher vom Array wird jetzt wieder freigegeben&quot;&lt;&lt;std::endl;
	delete [] mainArray;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::setSize(int range)
{
	T tempArray[index];
	bool transmit = false;

	if(index &gt; 0)
	{
		transmit = true;
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(transmit == true)
	{
		zeilen++;
		mainArray = new int[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	zeilen = range;
	delete [] mainArray;
	mainArray = new T[zeilen];
	std::cout&lt;&lt;&quot;neuer Speicher wurde allokiert&quot;&lt;&lt;std::endl;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::fillArray(T data)
{
	T tempArray[index];

	if(index &gt; 0)
	{
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(zeilen &lt;= index)
	{
		zeilen++;
		mainArray = new T[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	mainArray[index] = data;
	index++;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/950126</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950126</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 11:37:56 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 11:54:18 GMT]]></title><description><![CDATA[<p>Hallo,<br />
Bezogen auf dein Beispiel:</p>
<pre><code class="language-cpp">// Für konstante Objekte. D.h. wenn du ein dynArray&lt;T&gt;-Objekt als const deklarierst, wird diese Methode aufgerufen.
template &lt;class T&gt;
T&amp; dynArray&lt;T&gt;::operator[](size_t indx) { return mainArray[indx]; }

// Für nichtkonstante Objekte. Wird immer aufgerufen, wenn das aufrufende Objekt _nicht_ const ist.
template &lt;class T&gt;
const T&amp; dynArray&lt;T&gt;::operator[](size_t indx) const { return mainArray[indx]; }
</code></pre>
<p>Bzg. Mehr Infos zur Operatorenüberladung sei auf dein Lielings-Tutorial/Buch verwiesen. <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>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950138</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Mon, 26 Dec 2005 11:54:18 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 12:09:04 GMT]]></title><description><![CDATA[<p>danke so ähnlich sah mein versuch aus aus, buis auf das const <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="🙂"
    /><br />
aber ich bekomme immer noch diesen fehler!</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void fillArray(T data);

	void dispArray();

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}

	const T&amp; operator[](size_t indx) const;
	T&amp; operator[](size_t indx);
};

template &lt;class T&gt;
const T&amp; dynArray&lt;T&gt;::operator[](size_t indx) const { return mainArray[indx]; }

template &lt;class T&gt;
T&amp; dynArray&lt;T&gt;::operator[](size_t indx) { return mainArray[indx]; }
</code></pre>
<p>ich habe übrigens versucht:</p>
<pre><code class="language-cpp">T &amp;dynArray&lt;T&gt;::operator[] (int pos) //Referenz
{
	return *(mainArray+pos);
}
</code></pre>
<p>scheiß invaid comparison</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950143</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 12:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 12:15:30 GMT]]></title><description><![CDATA[<p>Hallo,<br />
in dem geposteten Code kann ich keinen Fehler entdecken. Poste doch mal ein minimales zu compilierendes Beispiel, in dem der Fehler auftritt. <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>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950151</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Mon, 26 Dec 2005 12:15:30 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 13:35:24 GMT]]></title><description><![CDATA[<p>sehr merkwürdig! bitte guck mal nach ob das auch wirklich dem original entsprechen würde! denn hier kann ich ohne probleme kompillieren auch ohne operator-überladung...<br />
d.h.:der fehler liegt wo anders <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstdlib&gt;

using namespace std;

template&lt;class T&gt;
class dynArray
{
private:
	T *Array;

public:
	dynArray() {Array = new T[25];}

	T getElement(int pos) {return Array[pos];}
};

template&lt;class T&gt;
void dArray(dynArray&lt;T&gt; array) {std::cout&lt;&lt; array.getElement(0) &lt;&lt;std::endl;}

int main(int argc, char *argv[])
{
  dynArray&lt;int&gt; foo;
  dArray(foo);

  return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/950201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950201</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 13:35:24 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 13:39:49 GMT]]></title><description><![CDATA[<p>icch poste mal alles zum selber probieren:</p>
<pre><code class="language-cpp">/***************************************************************************
 *   Copyright (C) 2005 by Daniel Frenzel   *
 *   dgdaniel@linux   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void fillArray(T data);

	void dispArray();

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}
/*
	const T&amp; operator[](size_t indx) const;
	T&amp; operator[](size_t indx);
*/
};
/*
template &lt;class T&gt;
const T&amp; dynArray&lt;T&gt;::operator[](size_t indx) const { return mainArray[indx]; }
template &lt;class T&gt;
T&amp; dynArray&lt;T&gt;::operator[](size_t indx) { return mainArray[indx]; }
*/
template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray() : index(0), zeilen(1)
{
	mainArray = new T[1];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(int size) : index(0), zeilen(size)
{
	mainArray = new T[size];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(dynArray&lt;T&gt; const &amp;ref) : zeilen(ref.zeilen), index(ref.index)
{
	for(int i = 0; i &lt; index; i++)
		mainArray[i] = ref.mainArray[i];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::~dynArray()
{
	std::cout&lt;&lt;&quot;Speicher vom Array wird jetzt wieder freigegeben&quot;&lt;&lt;std::endl;
	delete [] mainArray;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::setSize(int range)
{
	T tempArray[index];
	bool transmit = false;

	if(index &gt; 0)
	{
		transmit = true;
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(transmit == true)
	{
		zeilen++;
		mainArray = new int[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	zeilen = range;
	delete [] mainArray;
	mainArray = new T[zeilen];
	std::cout&lt;&lt;&quot;neuer Speicher wurde allokiert&quot;&lt;&lt;std::endl;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::fillArray(T data)
{
	T tempArray[index];

	if(index &gt; 0)
	{
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(zeilen &lt;= index)
	{
		zeilen++;
		mainArray = new T[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	mainArray[index] = data;
	index++;
}
/*
template&lt;class T&gt;
void dynArray&lt;T&gt;::dispArray()
{
	std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;getSize()&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;getIndex()&lt;&lt;std::endl;

	for(int i = 0; i &lt; index; i++)
		std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt; getMainArray(i) &lt;&lt;std::endl;
}
*/
</code></pre>
<pre><code class="language-cpp">/***************************************************************************
 *   Copyright (C) 2005 by Daniel Frenzel   *
 *   dgdaniel@linux   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;

#include &quot;dynarray.hpp&quot;

using namespace std;

template&lt;class T&gt;
void dArray(dynArray&lt;T&gt; array)
{
	std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;array.getSize()&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;array.getIndex()&lt;&lt;std::endl;

	for(int i = 0; i &lt; index; i++)
		std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt; array.getElement(i) &lt;&lt;std::endl;
}

int main(int argc, char *argv[])
{
  dynArray&lt;int&gt; b;
  dynArray&lt;int&gt; c;

  b.fillArray(1);
  c.fillArray(4);

  dArray(b);

  return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/950202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950202</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 13:39:49 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 15:23:01 GMT]]></title><description><![CDATA[<p>dgrat schrieb:</p>
<blockquote>
<p>denn hier kann ich ohne probleme kompillieren auch ohne operator-überladung...</p>
</blockquote>
<p>Hier verwendest du ja auch nicht das Konstrukt dynArray&lt;dynArray&lt;...&gt; &gt;, sondern hier steht T für einen builtin-datentyp. =&gt; Für Arrays aus Builtins ist der op[] defniert, desshalb kannst du auf ein Indiz über die Methode getElement() zugreifen..</p>
<p>Zu den Fehlern:</p>
<p>1. In der Funktion dArray() ist die Member-Variable index unbekannt. Du musst diese schon über die Methode getIndex() des entsprechenden Objekts ansprechen.<br />
2. In den Methoden setSize() und fillArray() versuchst du ein Array mit einer nicht-konstanten Größe zu definieren. Das geht nicht, da die größe eines Arrays dieser Art zur compile-Zeit bekannt sein muss. =&gt; Hantiere hier z.B. ebenfalls mit new[] und delete[].<br />
3. Deine Initialisierungsliste ist immer noch fehlerhaft.</p>
<p>beheb' diese Fehler mal, danach sollte das Programm laufen...</p>
<p>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950245</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Mon, 26 Dec 2005 15:23:01 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 18:43:50 GMT]]></title><description><![CDATA[<p>danke caipi!</p>
<ol>
<li>das mit dem index war doof... das war compilefehler</li>
<li>das mit den listen wusste ich gar 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="😕"
    /></li>
<li>an sich funktioniert doch die speicherverwaltung meines arrays, ich kann daten reinpacken, vergrößern etc.... ohne probleme<br />
merkwürdig ist aber das mir bei der member ausgabefunktion alles gut und schön angezeigt wird und bei der normalen funktion dArray bekomm ich nur einen speicherzugriffsfehler?</li>
</ol>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;

public:
	dynArray();
	dynArray(int size);
	dynArray(dynArray&lt;T&gt; const &amp;ref);

	~dynArray();

	void setSize(int range);
	void clearArray();
	void fillArray(T data);

	void dispArray();

	T getElement(int pos)
	{
		return mainArray[pos];
	}
	int getIndex()
	{
		return index;
	}
	int getSize()
	{
		return zeilen;
	}
/*
	const T&amp; operator[](size_t indx) const;
	T&amp; operator[](size_t indx);
*/
};
/*
template &lt;class T&gt;
const T&amp; dynArray&lt;T&gt;::operator[](size_t indx) const { return mainArray[indx]; }
template &lt;class T&gt;
T&amp; dynArray&lt;T&gt;::operator[](size_t indx) { return mainArray[indx]; }
*/
template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray() : zeilen(0), index(1)
{
	mainArray = new T[1];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(int size) : zeilen(0), index(1)
{
	mainArray = new T[size];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::dynArray(dynArray&lt;T&gt; const &amp;ref) : zeilen(ref.zeilen), index(ref.index)
{
	for(int i = 0; i &lt; index; i++)
		mainArray[i] = ref.mainArray[i];
}

template&lt;class T&gt;
dynArray&lt;T&gt;::~dynArray()
{
	std::cout&lt;&lt;&quot;Speicher vom Array wird jetzt wieder freigegeben&quot;&lt;&lt;std::endl;
	delete [] mainArray;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::setSize(int range)
{
	T tempArray[index];
	bool transmit = false;

	if(index &gt; 0)
	{
		transmit = true;
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(transmit == true)
	{
		zeilen++;
		mainArray = new int[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	zeilen = range;
	delete [] mainArray;
	mainArray = new T[zeilen];
	std::cout&lt;&lt;&quot;neuer Speicher wurde allokiert&quot;&lt;&lt;std::endl;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::fillArray(T data)
{
	T tempArray[index]; //lege buffer-array an

	if(index &gt; 0) //falls unser array leer ist wird es kopiert
	{
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(zeilen &lt;= index) //falls unser array zu klein ist
	{ //wird es vergroeßert und damit inhalt geloescht
		zeilen++;
		mainArray = new T[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	mainArray[index] = data; //daten werden in das array geschrieben
	index++;
}

template&lt;class T&gt;
void dynArray&lt;T&gt;::dispArray()
{
	std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;getSize()&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;getIndex()&lt;&lt;std::endl;

	for(int i = 0; i &lt; index; i++)
		std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt; getElement(i) &lt;&lt;std::endl;
}
</code></pre>
<p>im speziellen diese funktion:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
void dynArray&lt;T&gt;::fillArray(T data)
{
	T tempArray[index]; //lege buffer-array an

	if(index &gt; 0) //falls unser array leer ist wird es kopiert
	{
		for(int i = 0; i &lt; zeilen; i++)
			tempArray[i] = mainArray[i];
	}

	if(zeilen &lt;= index) //falls unser array zu klein ist
	{ //wird es vergroeßert und damit inhalt geloescht
		zeilen++;
		mainArray = new T[zeilen];

		for(int i = 0; i &lt; zeilen; i++)
			mainArray[i] = tempArray[i];

		std::cout&lt;&lt;&quot;Daten ueberschrieben&quot;&lt;&lt;std::endl;
	}

	mainArray[index] = data; //daten werden in das array geschrieben
	index++;
}
</code></pre>
<p>wo steht denn da nicht fest wie viel speicher benötigt wird? und warum funktioniert die member funktion im gegensatz zur diesr problemfunktion dArray()??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950360</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 18:43:50 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Mon, 26 Dec 2005 18:52:53 GMT]]></title><description><![CDATA[<blockquote>
<p>wo steht denn da nicht fest wie viel speicher benötigt wird? und warum funktioniert die member funktion im gegensatz zur diesr problemfunktion dArray()??</p>
</blockquote>
<p>sorry ich meinte, warum funktioniert die ausgabefunktion dispArray im gegensatz zur dArray funktion nicht? sind ja praktisch baugleich.<br />
und sicher spielst du deshalb auf das speicherzeugs an. aber der müsste theoretisch wirklich in ordnung sein, sonst würde dispArray nicht wunderbar funktioieren, bzw solche guten ergebnisse liefern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950362</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Mon, 26 Dec 2005 18:52:53 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Tue, 27 Dec 2005 10:15:21 GMT]]></title><description><![CDATA[<p>dgrat schrieb:</p>
<blockquote>
<p>danke caipi!</p>
<ol>
<li>das mit dem index war doof... das war compilefehler</li>
</ol>
</blockquote>
<p>Ich sehe trotzdem nicht, dass du ihn behoben hast.</p>
<p>dgrat schrieb:</p>
<blockquote>
<blockquote>
<p>wo steht denn da nicht fest wie viel speicher benötigt wird? und warum funktioniert die member funktion im gegensatz zur diesr problemfunktion dArray()??</p>
</blockquote>
<p>sorry ich meinte, warum funktioniert die ausgabefunktion dispArray im gegensatz zur dArray funktion nicht? sind ja praktisch baugleich.</p>
</blockquote>
<p>Nicht ganz. dArray ist nämlich _keine_ Memberfunktion von dynVec, weshalb sie _nicht_ auf private Datenelemente von dynVec zugreifen kann.</p>
<p>Schau dir am besten nochmal die Grundlagen, insbesondere Arrays, Das Prinzip der Kapselung, etc. an.</p>
<p>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950609</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Tue, 27 Dec 2005 10:15:21 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Tue, 27 Dec 2005 11:40:52 GMT]]></title><description><![CDATA[<p>zum index: funktion hab ich noch nicht gepostet<br />
[cpp]template&lt;class T&gt;<br />
void dArray(dynArray&lt;T&gt; array)<br />
{<br />
std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;array.getSize()&lt;&lt;std::endl;<br />
std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;array.getIndex()&lt;&lt;std::endl;</p>
<p>for(int i = 0; i &lt; <strong>array.getIndex()</strong>; i++)<br />
std::cout&lt;&lt;i&lt;&lt;&quot;.) &quot;&lt;&lt; array.getElement(i) &lt;&lt;std::endl;<br />
}[/cpp]</p>
<blockquote>
<p>dgrat schrieb:<br />
Zitat:<br />
wo steht denn da nicht fest wie viel speicher benötigt wird? und warum funktioniert die member funktion im gegensatz zur diesr problemfunktion dArray()??</p>
<p>sorry ich meinte, warum funktioniert die ausgabefunktion dispArray im gegensatz zur dArray funktion nicht? sind ja praktisch baugleich.</p>
<p>Nicht ganz. dArray ist nämlich _keine_ Memberfunktion von dynVec, weshalb sie _nicht_ auf private Datenelemente von dynVec zugreifen kann.</p>
<p>Schau dir am besten nochmal die Grundlagen, insbesondere Arrays, Das Prinzip der Kapselung, etc. an.</p>
<p>Gruß Caipi</p>
</blockquote>
<p>aber sie benutzt doch öffentliche funktionen der klasse?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950653</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Tue, 27 Dec 2005 11:40:52 GMT</pubDate></item><item><title><![CDATA[Reply to template klasse verschachteln... on Tue, 27 Dec 2005 12:26:40 GMT]]></title><description><![CDATA[<p>ich sehe echt keinen grund dafür dass ich einen speicherzugriffsfehler bekomme weil ich auf private normale variablen zugreife. und zwar über normale funktionen...<br />
hier ein beispiel:</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#include &lt;config.h&gt;
#endif

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;

using namespace std;

template&lt;class T&gt;
class a
{
private: 
	int b;
public:
	a(int c)
	{
		b = c;
	}

	int getB()
	{
		return b;
	}
};
template&lt;class T&gt;
void getnB(a&lt;T&gt; foo)
{
cout&lt;&lt;foo.getB();
}

int main(int argc, char *argv[])
{
  a&lt;int&gt; foo(6);
  getnB(foo);

  return EXIT_SUCCESS;
}
</code></pre>
<p>vergleicht man das mit meins, stellt man fest das es keinen unterschied gibt...:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class dynArray
{
private:
	T *mainArray;

	int zeilen;
	int index;
	int dimArray;
public:
...
	int getIndex()
	{
		return index;
	}
	int getZeilen()
	{
		return zeilen;
	}
};
template&lt;class T&gt;
void dArray(dynArray&lt;T&gt; array)
{
	std::cout&lt;&lt;&quot;SIZE: &quot;&lt;&lt;array.getZeilen()&lt;&lt;std::endl;
	std::cout&lt;&lt;&quot;INDEX: &quot;&lt;&lt;array.getIndex()&lt;&lt;std::endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/950674</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950674</guid><dc:creator><![CDATA[dgrat]]></dc:creator><pubDate>Tue, 27 Dec 2005 12:26:40 GMT</pubDate></item></channel></rss>