<?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 Template Problem bei Initialisierung]]></title><description><![CDATA[<p>Hallöchen!</p>
<p>Ich sitze schon geraume Zeit vor dem Problem, dass ich Programme ohne einige der Standartbibliotheken wie STL schreiben muss. Also dachte ich, dass ich mir die Datenstrukturen eben selbst erstelle. Ich habe einen AVL Baum und einen Vector implementiert die auch mit primitiven Datentypen einwandfrei funktionieren. Wenn ich aber einen AVL Baum in einen Vector speichern will schmiert das Programm ab.<br />
Hier einige Code-Auszüge:</p>
<pre><code class="language-cpp">int main() {
  AVL_Tree&lt;int&gt; t;
  t.insert(8);
  t.insert(11);
  t.insert(2);
  ...
  Vector&lt; int, AVL_Tree &gt; avlvec;
  avlvec.addFirst(t);
  cout &lt;&lt; &quot;t inserted&quot;&lt;&lt; endl;
  return 0;
}
</code></pre>
<p>Die Ausgabe sieht wie folgt aus:<br />
first setVal<br />
zuweisung<br />
8<br />
zuweisung2<br />
zuweisung fertig<br />
index set<br />
size ++<br />
make: *** [test] Segmentation fault</p>
<p>Quellcode aus den benutzten Klassen:</p>
<pre><code class="language-cpp">template &lt;typename T, template &lt;typename&gt; class Cont&gt; class Vector {
private:
  VectorNode&lt;T, Cont&gt; *first, *last;
  int size;
public:
  Vector () {
    size = 0;
    first = new VectorNode&lt;T,Cont&gt; ();
    last = first;
  }
  ...
  void addFirst(Cont&lt;T&gt; t) {
    if (size == 0) {
      cout &lt;&lt; &quot;first setVal&quot; &lt;&lt; endl;
      first-&gt;setValue(t);
      first-&gt;setIndex(0);
      cout &lt;&lt; &quot;index set&quot; &lt;&lt; endl;
      size++;
      cout &lt;&lt; &quot;size ++&quot; &lt;&lt; endl;
      first-&gt;getValue().inOrder(cout);  //hier scheint es zu knallen
      cout &lt;&lt; &quot;return&quot; &lt;&lt; endl;
      return;
    }
    VectorNode&lt;T,Cont&gt; *new_first = new VectorNode&lt;T,Cont&gt; (t);
    VectorNode&lt;T,Cont&gt; *tmp = first;
    new_first-&gt;setNext(tmp);
    first = new_first;
    tmp-&gt;setPrev(first);
    tmp-&gt;setIndex(1);
    size++;
  }
  ...
  virtual ~Vector() {
    delete first;
  }
};

template &lt;typename T, template &lt;typename&gt; class Cont&gt; class VectorNode {
private:
  VectorNode&lt;T, Cont&gt; *prev, *next;
  int index;
  Cont&lt;T&gt; value;
public:
  VectorNode() {
    next = prev = NULL;
    index = -1;
  }

  VectorNode(Cont&lt;T&gt; t) {
    value = t;
    cout &lt;&lt; &quot;VectorNode Baum zugewiesen&quot; &lt;&lt; endl;
    next = NULL;
    prev = NULL;
    index = 0;
    cout &lt;&lt; &quot;GraphNode erstellt&quot; &lt;&lt; endl;
  }
  ...
  Cont&lt;T&gt; getValue() {
    if (index &gt;= 0) {
      return value;
    }
  }
  ...
  virtual ~VectorNode() {
    delete next;
  }
};

template&lt;class T&gt; class AVL_Tree {
private:
  T value;
  AVL_Tree&lt;T&gt; *left;
  AVL_Tree&lt;T&gt; *right;
  int height, size;
  ...
  AVL_Tree() {
    value = T();
    left = NULL;
    right = NULL;
    size = 0;
    height = 0;
  }

  void operator=(AVL_Tree&lt;T&gt; &amp;other) {
    cout &lt;&lt; &quot;zuweisung&quot; &lt;&lt; endl;
    value = other.value;
    cout &lt;&lt; value &lt;&lt; &quot; &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;zuweisung2&quot; &lt;&lt; endl;
    left = other.left;
    right = other.right;
    size = other.size;
    height = other.height;
    cout &lt;&lt; &quot;zuweisung fertig&quot; &lt;&lt; endl;
  }

  virtual ~AVL_Tree() {
    delete left;
    delete right;
  }
  ...
};
</code></pre>
<p>Also wie gesagt es hat alles ganz wunderbar funktioniert bis ich versuchte die Klassen zu kombinieren. Hoffentlich gibt es hier einen Experten, der oder die mir helfen kann. Danke im Voraus <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/topic/269132/template-template-problem-bei-initialisierung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 08:55:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/269132.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Jun 2010 15:09:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 15:42:45 GMT]]></title><description><![CDATA[<p>Hallöchen!</p>
<p>Ich sitze schon geraume Zeit vor dem Problem, dass ich Programme ohne einige der Standartbibliotheken wie STL schreiben muss. Also dachte ich, dass ich mir die Datenstrukturen eben selbst erstelle. Ich habe einen AVL Baum und einen Vector implementiert die auch mit primitiven Datentypen einwandfrei funktionieren. Wenn ich aber einen AVL Baum in einen Vector speichern will schmiert das Programm ab.<br />
Hier einige Code-Auszüge:</p>
<pre><code class="language-cpp">int main() {
  AVL_Tree&lt;int&gt; t;
  t.insert(8);
  t.insert(11);
  t.insert(2);
  ...
  Vector&lt; int, AVL_Tree &gt; avlvec;
  avlvec.addFirst(t);
  cout &lt;&lt; &quot;t inserted&quot;&lt;&lt; endl;
  return 0;
}
</code></pre>
<p>Die Ausgabe sieht wie folgt aus:<br />
first setVal<br />
zuweisung<br />
8<br />
zuweisung2<br />
zuweisung fertig<br />
index set<br />
size ++<br />
make: *** [test] Segmentation fault</p>
<p>Quellcode aus den benutzten Klassen:</p>
<pre><code class="language-cpp">template &lt;typename T, template &lt;typename&gt; class Cont&gt; class Vector {
private:
  VectorNode&lt;T, Cont&gt; *first, *last;
  int size;
public:
  Vector () {
    size = 0;
    first = new VectorNode&lt;T,Cont&gt; ();
    last = first;
  }
  ...
  void addFirst(Cont&lt;T&gt; t) {
    if (size == 0) {
      cout &lt;&lt; &quot;first setVal&quot; &lt;&lt; endl;
      first-&gt;setValue(t);
      first-&gt;setIndex(0);
      cout &lt;&lt; &quot;index set&quot; &lt;&lt; endl;
      size++;
      cout &lt;&lt; &quot;size ++&quot; &lt;&lt; endl;
      first-&gt;getValue().inOrder(cout);  //hier scheint es zu knallen
      cout &lt;&lt; &quot;return&quot; &lt;&lt; endl;
      return;
    }
    VectorNode&lt;T,Cont&gt; *new_first = new VectorNode&lt;T,Cont&gt; (t);
    VectorNode&lt;T,Cont&gt; *tmp = first;
    new_first-&gt;setNext(tmp);
    first = new_first;
    tmp-&gt;setPrev(first);
    tmp-&gt;setIndex(1);
    size++;
  }
  ...
  virtual ~Vector() {
    delete first;
  }
};

template &lt;typename T, template &lt;typename&gt; class Cont&gt; class VectorNode {
private:
  VectorNode&lt;T, Cont&gt; *prev, *next;
  int index;
  Cont&lt;T&gt; value;
public:
  VectorNode() {
    next = prev = NULL;
    index = -1;
  }

  VectorNode(Cont&lt;T&gt; t) {
    value = t;
    cout &lt;&lt; &quot;VectorNode Baum zugewiesen&quot; &lt;&lt; endl;
    next = NULL;
    prev = NULL;
    index = 0;
    cout &lt;&lt; &quot;GraphNode erstellt&quot; &lt;&lt; endl;
  }
  ...
  Cont&lt;T&gt; getValue() {
    if (index &gt;= 0) {
      return value;
    }
  }
  ...
  virtual ~VectorNode() {
    delete next;
  }
};

template&lt;class T&gt; class AVL_Tree {
private:
  T value;
  AVL_Tree&lt;T&gt; *left;
  AVL_Tree&lt;T&gt; *right;
  int height, size;
  ...
  AVL_Tree() {
    value = T();
    left = NULL;
    right = NULL;
    size = 0;
    height = 0;
  }

  void operator=(AVL_Tree&lt;T&gt; &amp;other) {
    cout &lt;&lt; &quot;zuweisung&quot; &lt;&lt; endl;
    value = other.value;
    cout &lt;&lt; value &lt;&lt; &quot; &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;zuweisung2&quot; &lt;&lt; endl;
    left = other.left;
    right = other.right;
    size = other.size;
    height = other.height;
    cout &lt;&lt; &quot;zuweisung fertig&quot; &lt;&lt; endl;
  }

  virtual ~AVL_Tree() {
    delete left;
    delete right;
  }
  ...
};
</code></pre>
<p>Also wie gesagt es hat alles ganz wunderbar funktioniert bis ich versuchte die Klassen zu kombinieren. Hoffentlich gibt es hier einen Experten, der oder die mir helfen kann. Danke im Voraus <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/1914793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914793</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sat, 19 Jun 2010 15:42:45 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 15:14:54 GMT]]></title><description><![CDATA[<p>&gt; Ich sitze schon geraume Zeit vor dem Problem, dass ich Programme ohne einige der Standartbibliotheken wie STL schreiben muss.</p>
<p>Wieso das denn? Wer sagt das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914796</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914796</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sat, 19 Jun 2010 15:14:54 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 15:22:06 GMT]]></title><description><![CDATA[<p>Weil unsere Übungsleiterin offensichtlich der Meinung ist, dass es sonst zu leicht wäre...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914800</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sat, 19 Jun 2010 15:22:06 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 15:47:29 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Cont&lt;T&gt; getValue()
{
    if (index &gt;= 0) {
      return value;
    }
}
</code></pre>
<p><code>else</code> ? -&gt; nix -&gt; puff</p>
<p>Der GCC kompiliert das ohne Warnung oder? Das hat mich auch schon öfter genervt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914813</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sat, 19 Jun 2010 15:47:29 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 15:50:18 GMT]]></title><description><![CDATA[<p>vielleicht kein schöner stil aber auch kein problem. ich benutze g++ und der meckert schon oft genug^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914815</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sat, 19 Jun 2010 15:50:18 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 15:52:04 GMT]]></title><description><![CDATA[<p>Das sollte kein Stilgemecker sein, sondern dort vermute ich nach Überfliegen den Fehler.</p>
<pre><code class="language-cpp">first-&gt;getValue().inOrder(cout);  //hier scheint es zu knallen
</code></pre>
<p>getValue gibt nix zurück worauf du inOrder aufrufen könntest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914816</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sat, 19 Jun 2010 15:52:04 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 16:09:12 GMT]]></title><description><![CDATA[<p>ich bin schon ein kkleines sück weiter gekommen und zwar habe ich den überladenen operator im AVL_Baum rausgenommen und durch einen copyconstruktor ersetzt jetzt knallt es erst später <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1914822</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914822</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sat, 19 Jun 2010 16:09:12 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 16:22:53 GMT]]></title><description><![CDATA[<p>ich habe für alle klassen entsprechende copy konstruktoren geschrieben und nun läuft die main durch. allerdings stehe ich nun vor dem problem, dass dann ein seg-fault entsteht:</p>
<p>==3075== HEAP SUMMARY:<br />
==3075== in use at exit: 40 bytes in 1 blocks<br />
==3075== total heap usage: 23 allocs, 38 frees, 584 bytes allocated</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914825</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sat, 19 Jun 2010 16:22:53 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 17:27:34 GMT]]></title><description><![CDATA[<p>ichwillkaffee schrieb:</p>
<blockquote>
<p>ich habe für alle klassen entsprechende copy konstruktoren geschrieben und nun läuft die main durch. allerdings stehe ich nun vor dem problem, dass dann ein seg-fault entsteht:</p>
<p>==3075== HEAP SUMMARY:<br />
==3075== in use at exit: 40 bytes in 1 blocks<br />
==3075== total heap usage: 23 allocs, 38 frees, 584 bytes allocated</p>
</blockquote>
<p>Du gibst scheinbar Speicher doppelt frei.</p>
<p>In dem Code, den du gepostet hast allerdings (glaube ich) nicht.</p>
<p>Vermutlich erstellt dein Copy-Konstruktor keine neuen Knoten, sondern<br />
verwendet die alten Zeiger und gibt sie beim delete somit doppelt frei.</p>
<p>Hast du den CopyConstructor denn implementiert?<br />
Falls nein, hab ich wohl recht <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/1914840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914840</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 19 Jun 2010 17:27:34 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 17:38:12 GMT]]></title><description><![CDATA[<p>Der Copy-Constructor sollte (ungetestet) ungefähr so aussehen...</p>
<pre><code class="language-cpp">public:
AVL_Tree(const AVL_Tree&lt;T&gt;&amp; toCopy) {
    value = toCopy.value;
    if(toCopy.left != NULL){
        left = new AVL_Tree&lt;T&gt;(*toCopy.left);
    } else{
        left = NULL;
    }
    if(toCopy.right != NULL){
        right=new AVL_Tree&lt;T&gt;(*toCopy.right);
    } else{
        right = NULL;
    }
    size = toCopy.size;
    height = toCopy.height;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1914842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914842</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 19 Jun 2010 17:38:12 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 17:38:58 GMT]]></title><description><![CDATA[<p>Die Konstruktoren sind implementiert:</p>
<pre><code class="language-cpp">AVL_Tree(const AVL_Tree&lt;T&gt; &amp;other) {
    value = other.value;
    left = other.left;
    right = other.right;
    size = other.size;
    height = other.height;
  }

  Vector (const Vector&lt;T,Cont&gt; &amp;other) {
    first = other.first;
    last = other.last;
    size = other.size;
  }

  VectorNode(const VectorNode&lt;T,Cont&gt; &amp;other){
    prev = other.prev;
    next = other.next;
    index = other.index;
    value = other.value;
  }
</code></pre>
<p>Ich habe an den Destruktoren nichts geändert... sehe auch noch nicht wo der Fehler sein könnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914844</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sat, 19 Jun 2010 17:38:58 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 17:43:20 GMT]]></title><description><![CDATA[<p>Bei deinem</p>
<pre><code class="language-cpp">void operator=(AVL_Tree&lt;T&gt; &amp;other)
</code></pre>
<p>, den du ja rausgenommen hast, besteht übrigens genau das gleiche Problem...</p>
<p>Du kopierst nur Zeiger auf Objekte, die beim Löschen eines der beiden<br />
AVL__Bäume zerstört werden und dann gibts den Segmentation-Fault</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914846</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 19 Jun 2010 17:43:20 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 17:44:04 GMT]]></title><description><![CDATA[<p>Du kopierst da nur die Zeiger. Nach so einer Kopie wird dann in zwei Destruktoren delete für left und right auf die gleiche Instanz aufgerufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914847</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Sat, 19 Jun 2010 17:44:04 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sat, 19 Jun 2010 17:53:13 GMT]]></title><description><![CDATA[<p>EDIT: berndbrot hat recht, ich war nur zu langsam</p>
<p>ichwillkaffee schrieb:</p>
<blockquote>
<p>Die Konstruktoren sind implementiert:</p>
<pre><code class="language-cpp">AVL_Tree(const AVL_Tree&lt;T&gt; &amp;other) {
    value = other.value;
    left = other.left;
    right = other.right;
    size = other.size;
    height = other.height;
  }

  Vector (const Vector&lt;T,Cont&gt; &amp;other) {
    first = other.first;
    last = other.last;
    size = other.size;
  }

  VectorNode(const VectorNode&lt;T,Cont&gt; &amp;other){
    prev = other.prev;
    next = other.next;
    index = other.index;
    value = other.value;
  }
</code></pre>
<p>Ich habe an den Destruktoren nichts geändert... sehe auch noch nicht wo der Fehler sein könnte.</p>
</blockquote>
<p>Wieso auch? <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>Also...</p>
<p>Sobald du eine Kopie von z.B. AVL_Baum erstellst, kopiert er die Zeiger<br />
auf die Kind-Knoten.<br />
Wenn du deinen AVL_Baum jedoch löschst, löschst du auch die Kind-Knoten,<br />
die dann in deinen Kopien (oder im Original) auch nicht mehr verfügbar sind.<br />
Alle Kind-Knoten existieren nur einmal!!!</p>
<p>EDIT2:<br />
Das gleiche Problem besteht auch bei deinem Vector (, der übrigens ne List ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ),<br />
jedoch mußt du hier aufpassen, dass insbesondere last und prev, auf deine neu erstellten<br />
VectorNode verweist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914848</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 19 Jun 2010 17:53:13 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sun, 20 Jun 2010 07:45:56 GMT]]></title><description><![CDATA[<p>jeah!!! ich hab es gelöst. man braucht nicht nur einen copy constructor sondern muss auch den &quot;=&quot; operator überschreiben *grooße freude*</p>
<pre><code class="language-cpp">AVL_Tree() {
    left = NULL;
    right = NULL;
    size = 0;
    height = 0;
  }

  AVL_Tree(T &amp;t) {
    value = t;
    left = NULL;
    right = NULL;
    size = 1;
    height = 0;
  }

  AVL_Tree(const AVL_Tree&lt;T&gt; &amp;other) {
    value = other.value;
    if (other.left != NULL) {
      left = new AVL_Tree&lt;T&gt; (*other.left);;
    } else {
      left = NULL;
    }
    if (other.right != NULL) {
      right = new AVL_Tree&lt;T&gt; (*other.right);
    } else {
      right = NULL;
    }
    size = other.size;
    height = other.height;
  }

  void operator=(AVL_Tree&lt;T&gt; &amp;other) {
    cout &lt;&lt; &quot;assignment operator &quot; &lt;&lt; endl;
    value = other.value;
    if (other.left != NULL) {
      left = new AVL_Tree&lt;T&gt; (*other.left);
    } else {
      left = NULL;
    }
    if (other.right != NULL) {
      right = new AVL_Tree&lt;T&gt; (*other.right);
    } else {
      right = NULL;
    }
    size = other.size;
    height = other.height;
  }

  virtual ~AVL_Tree() {
    delete left;
    delete right;
  }
</code></pre>
<p>danke an alle die geholfen haben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> ich würd euch ja einen ausgeben...<br />
kann man das thema irgendwo als gelöst abhaken?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1914973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1914973</guid><dc:creator><![CDATA[ichwillkaffee]]></dc:creator><pubDate>Sun, 20 Jun 2010 07:45:56 GMT</pubDate></item><item><title><![CDATA[Reply to Template Template Problem bei Initialisierung on Sun, 20 Jun 2010 09:46:31 GMT]]></title><description><![CDATA[<p>Schau dir doch mal das Copy/Swap Idiom an für den Zuweisungsoperator. Im Moment ist das eher unschön wegen Code Verdopplung.<br />
Initialisierungslisten wären auch mal etwas zum nachschlagen.</p>
<blockquote>
<p>kann man das thema irgendwo als gelöst abhaken?</p>
</blockquote>
<p>Viele ändern den Titel indem sie ein [Gelöst] vorne anhängen.</p>
<p>Wenn du einen ausgeben willst, dann musst du ans Forentreffen kommen. <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/1915006</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1915006</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 20 Jun 2010 09:46:31 GMT</pubDate></item></channel></rss>