<?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[code bewerten]]></title><description><![CDATA[<p>hallo..</p>
<p>da ich noch ziemlich unerfahren im progn bin, bitte ich euch, mal meinen code durchzuschauen, und tips zu geben..</p>
<p>es ist eine liste die pointer aufnimmt.<br />
(ich hatte vor ein paar tagen ein problem, und hab damals schon eine fruehere vers. gepostet..)</p>
<p>ps:<br />
hat sich jetzt schon ausgezahlt: ich hab im kdevelop die &quot;quelltext formatieren&quot; funktion gefunden. davor hab ich nur die einstellungen dafuer gekannt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>mylistelement.h</p>
<pre><code class="language-cpp">#ifndef MYLISTELEMENT_H
#define MYLISTELEMENT_H

// #include &quot;mylist.h&quot;
template &lt;class T&gt;
class MyList;

/**
@author Adam Celarek
*/

template &lt;class T&gt;
class MyListElement
{
      //    private:
   public:
      MyListElement( T* el );
      ~MyListElement();

      MyListElement* next;
      MyListElement* prev;
      T* element;

      friend class MyList&lt;T&gt;;
};

///########################################################################################///
///########################################################################################///
///########################################################################################///

///#### con- / destructor
template &lt;class T&gt;
MyListElement&lt;T&gt;::MyListElement( T* element )
{
   this-&gt;element = element;
   this-&gt;next = NULL;
   this-&gt;prev = NULL;
}

template &lt;class T&gt;
MyListElement&lt;T&gt;::~MyListElement()
{
   delete element;
   this-&gt;next = NULL;
   this-&gt;prev = NULL;
}

#endif
</code></pre>
<p>mylist.h</p>
<pre><code class="language-cpp">#ifndef MYLIST_H
#define MYLIST_H

#include &quot;mylistelement.h&quot;

#include &lt;iostream&gt;
using namespace std;

/**
@author Adam Celarek
*/

template &lt;class T&gt;
class MyList
{
   public:
      MyList();
      ~MyList();
      void append( T* element );          // appends T* element and resets the next() function
      bool deleteCurrentElement();        // delete previously returned_element, and sets the returned_element pointer
      // to NULL. so a current() after a deleteCurrentElement() will always give a NULL
      // returns false if the returned_element pointer is NULL or if the list_size is 0
      // otherwise it returnes true.
      int size();                         // returns list_size;
      T* next();                          // returns next_element; if the last element of the list
      // have been already returned, the function returns NULL
      T* current();                       // returns previously returned_element or NULL (if it isn't available)
      T* first();                         // returns first elem, and resets the next() function
   private:
      MyListElement&lt;T&gt;* first_element;
      MyListElement&lt;T&gt;* returned_element; // this element may be deleted / was returned by next (if not, then it's NULL)
      MyListElement&lt;T&gt;* next_element;     // this element will be returned in the next step
      MyListElement&lt;T&gt;* last_element;
      int list_size;
};

///########################################################################################///
///########################################################################################///
///########################################################################################///

///####    con/de-tructors    ####
template &lt;class T&gt;
MyList&lt;T&gt;::MyList()
{
   first_element = NULL;
   returned_element = NULL;
   next_element = first_element;
   list_size = 0;
}
template &lt;class T&gt;
MyList&lt;T&gt;::~MyList()
{
   MyListElement&lt;T&gt;* current_element;
   current_element = this-&gt;first_element;       // begin at the first element
   while ( current_element )
   {
      first_element = current_element-&gt;next;
      delete current_element;                   // deleting all elements
      current_element = first_element;
   }
}

///####    acces    ####

/*!
    \fn MyList::append()
 */
template &lt;class T&gt;
void MyList&lt;T&gt;::append( T* element )
{
   MyListElement&lt;T&gt;* new_element = new MyListElement&lt;T&gt;( element );
   // new element

   // 2 cases:
   // 1. there are no elements in the list
   // 2. there are elements in the list
   if ( list_size == 0 )   // case 1: no elements in the list
   {
      first_element = new_element;
      last_element = new_element;
   }
   else                                   // case 2: the new element will be appended to the end of the list
   {
      last_element-&gt;next = new_element;
      new_element-&gt;prev = last_element;
      last_element = new_element;
   }

   first();                               // resets the next() function
   list_size++;
}

/*!
    \fn MyList::deleteCurrentElement()
 */
template &lt;class T&gt;
bool MyList&lt;T&gt;::deleteCurrentElement()
{
   //cases:
   // 0. no elements in the list
   // 1. first elemement
   // 2. in the middle
   // 3. at the end

   // 0. no elements
   if ( returned_element == NULL || list_size == 0 )
   {
      return false;
   }
   // 1. deleteting the first element
   else if ( returned_element == first_element )
   {
      if ( next_element != NULL )
         next_element-&gt;prev = NULL;
      first_element = next_element;
   }
   // 3. case, at the end
   else if ( returned_element == last_element )
   {
      returned_element-&gt;prev-&gt;next = NULL;      // the pointer doesn't must be checked. If there was a previous
      // element, it would have been cought by the first case
      last_element = returned_element-&gt;prev;
   }
   // 2. case, in the middle
   else
   {
      // change the pointer of the prev. and next element
      // no check, the same reason as in clause 3
      returned_element-&gt;next-&gt;prev = returned_element-&gt;prev;
      returned_element-&gt;prev-&gt;next = returned_element-&gt;next;
   }
   delete returned_element;                     // kill the element and set returned_element to NULL
   list_size--;                                 // finally the list decreases
   return true;
}

/*!
    \fn MyList::first()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::first()
{
   returned_element = NULL;                     // reseting the variables for the next() method
   next_element = first_element;

   if ( first_element != NULL )
      return first_element-&gt;element;
   else
      return NULL;
}

/*!
    \fn MyList::next()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::next()
{
   if ( next_element == NULL )
   {
      returned_element = NULL;             // the next_element is only NULL, if there aren't any elements
      return NULL;                         // in the list (set by first()), or if the last position was already returned
   }                                       // it's even a check, so that the else clause can't make a segmentation fault
   else
   {
      returned_element = next_element;
      next_element = returned_element-&gt;next;
      return returned_element-&gt;element;
   }
}

/*!
    \fn MyList::current()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::current()
{
   if ( returned_element != NULL )
      return returned_element-&gt;element;
   else
      return NULL;
}

///####   properties    ####
/*!
    \fn MyList::size()
 */
template &lt;class T&gt;
int MyList&lt;T&gt;::size()
{
   return list_size;
}

#endif
</code></pre>
<p>mfg aMan..</p>
<p>und danke schon mal..</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123762/code-bewerten</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 20:59:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123762.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Oct 2005 17:49:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 17:50:22 GMT]]></title><description><![CDATA[<p>hallo..</p>
<p>da ich noch ziemlich unerfahren im progn bin, bitte ich euch, mal meinen code durchzuschauen, und tips zu geben..</p>
<p>es ist eine liste die pointer aufnimmt.<br />
(ich hatte vor ein paar tagen ein problem, und hab damals schon eine fruehere vers. gepostet..)</p>
<p>ps:<br />
hat sich jetzt schon ausgezahlt: ich hab im kdevelop die &quot;quelltext formatieren&quot; funktion gefunden. davor hab ich nur die einstellungen dafuer gekannt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>mylistelement.h</p>
<pre><code class="language-cpp">#ifndef MYLISTELEMENT_H
#define MYLISTELEMENT_H

// #include &quot;mylist.h&quot;
template &lt;class T&gt;
class MyList;

/**
@author Adam Celarek
*/

template &lt;class T&gt;
class MyListElement
{
      //    private:
   public:
      MyListElement( T* el );
      ~MyListElement();

      MyListElement* next;
      MyListElement* prev;
      T* element;

      friend class MyList&lt;T&gt;;
};

///########################################################################################///
///########################################################################################///
///########################################################################################///

///#### con- / destructor
template &lt;class T&gt;
MyListElement&lt;T&gt;::MyListElement( T* element )
{
   this-&gt;element = element;
   this-&gt;next = NULL;
   this-&gt;prev = NULL;
}

template &lt;class T&gt;
MyListElement&lt;T&gt;::~MyListElement()
{
   delete element;
   this-&gt;next = NULL;
   this-&gt;prev = NULL;
}

#endif
</code></pre>
<p>mylist.h</p>
<pre><code class="language-cpp">#ifndef MYLIST_H
#define MYLIST_H

#include &quot;mylistelement.h&quot;

#include &lt;iostream&gt;
using namespace std;

/**
@author Adam Celarek
*/

template &lt;class T&gt;
class MyList
{
   public:
      MyList();
      ~MyList();
      void append( T* element );          // appends T* element and resets the next() function
      bool deleteCurrentElement();        // delete previously returned_element, and sets the returned_element pointer
      // to NULL. so a current() after a deleteCurrentElement() will always give a NULL
      // returns false if the returned_element pointer is NULL or if the list_size is 0
      // otherwise it returnes true.
      int size();                         // returns list_size;
      T* next();                          // returns next_element; if the last element of the list
      // have been already returned, the function returns NULL
      T* current();                       // returns previously returned_element or NULL (if it isn't available)
      T* first();                         // returns first elem, and resets the next() function
   private:
      MyListElement&lt;T&gt;* first_element;
      MyListElement&lt;T&gt;* returned_element; // this element may be deleted / was returned by next (if not, then it's NULL)
      MyListElement&lt;T&gt;* next_element;     // this element will be returned in the next step
      MyListElement&lt;T&gt;* last_element;
      int list_size;
};

///########################################################################################///
///########################################################################################///
///########################################################################################///

///####    con/de-tructors    ####
template &lt;class T&gt;
MyList&lt;T&gt;::MyList()
{
   first_element = NULL;
   returned_element = NULL;
   next_element = first_element;
   list_size = 0;
}
template &lt;class T&gt;
MyList&lt;T&gt;::~MyList()
{
   MyListElement&lt;T&gt;* current_element;
   current_element = this-&gt;first_element;       // begin at the first element
   while ( current_element )
   {
      first_element = current_element-&gt;next;
      delete current_element;                   // deleting all elements
      current_element = first_element;
   }
}

///####    acces    ####

/*!
    \fn MyList::append()
 */
template &lt;class T&gt;
void MyList&lt;T&gt;::append( T* element )
{
   MyListElement&lt;T&gt;* new_element = new MyListElement&lt;T&gt;( element );
   // new element

   // 2 cases:
   // 1. there are no elements in the list
   // 2. there are elements in the list
   if ( list_size == 0 )   // case 1: no elements in the list
   {
      first_element = new_element;
      last_element = new_element;
   }
   else                                   // case 2: the new element will be appended to the end of the list
   {
      last_element-&gt;next = new_element;
      new_element-&gt;prev = last_element;
      last_element = new_element;
   }

   first();                               // resets the next() function
   list_size++;
}

/*!
    \fn MyList::deleteCurrentElement()
 */
template &lt;class T&gt;
bool MyList&lt;T&gt;::deleteCurrentElement()
{
   //cases:
   // 0. no elements in the list
   // 1. first elemement
   // 2. in the middle
   // 3. at the end

   // 0. no elements
   if ( returned_element == NULL || list_size == 0 )
   {
      return false;
   }
   // 1. deleteting the first element
   else if ( returned_element == first_element )
   {
      if ( next_element != NULL )
         next_element-&gt;prev = NULL;
      first_element = next_element;
   }
   // 3. case, at the end
   else if ( returned_element == last_element )
   {
      returned_element-&gt;prev-&gt;next = NULL;      // the pointer doesn't must be checked. If there was a previous
      // element, it would have been cought by the first case
      last_element = returned_element-&gt;prev;
   }
   // 2. case, in the middle
   else
   {
      // change the pointer of the prev. and next element
      // no check, the same reason as in clause 3
      returned_element-&gt;next-&gt;prev = returned_element-&gt;prev;
      returned_element-&gt;prev-&gt;next = returned_element-&gt;next;
   }
   delete returned_element;                     // kill the element and set returned_element to NULL
   list_size--;                                 // finally the list decreases
   return true;
}

/*!
    \fn MyList::first()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::first()
{
   returned_element = NULL;                     // reseting the variables for the next() method
   next_element = first_element;

   if ( first_element != NULL )
      return first_element-&gt;element;
   else
      return NULL;
}

/*!
    \fn MyList::next()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::next()
{
   if ( next_element == NULL )
   {
      returned_element = NULL;             // the next_element is only NULL, if there aren't any elements
      return NULL;                         // in the list (set by first()), or if the last position was already returned
   }                                       // it's even a check, so that the else clause can't make a segmentation fault
   else
   {
      returned_element = next_element;
      next_element = returned_element-&gt;next;
      return returned_element-&gt;element;
   }
}

/*!
    \fn MyList::current()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::current()
{
   if ( returned_element != NULL )
      return returned_element-&gt;element;
   else
      return NULL;
}

///####   properties    ####
/*!
    \fn MyList::size()
 */
template &lt;class T&gt;
int MyList&lt;T&gt;::size()
{
   return list_size;
}

#endif
</code></pre>
<p>mfg aMan..</p>
<p>und danke schon mal..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896424</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Wed, 19 Oct 2005 17:50:22 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 18:21:51 GMT]]></title><description><![CDATA[<p>NULL ist C, in C++ _sollte_ man 0 nehmen.</p>
<p>In Header Dateien NIEMALS einen Namespace öffnen (using namespace std;), es sei denn, du weißt wirklich genau was du tust.</p>
<p>Die ganzen get-Methoden (size (), current () etc.) sollte man als Const-Methoden auszeichnen.</p>
<p>list_size ist entweder size_t oder unsigned.</p>
<p>Es kann praktisch sein, Membervariablen mit einem Präfix zu versehen (z.B. m, m_, _).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896450</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Wed, 19 Oct 2005 18:21:51 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 18:31:13 GMT]]></title><description><![CDATA[<p>jo, thx schon mal..<br />
werd das morgen im zug korigieren..</p>
<p>welchen vorteil haben denn const methoden?</p>
<p>das #include &lt;iostream&gt; sollte eigentlich eh nicht mehr drinn sein (war zum debugen)</p>
<p>sonst noch tipps?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896459</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Wed, 19 Oct 2005 18:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 19:03:14 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10156">@aman</a>: das sie am Objekt/Exemplar selbst keine Aenderungen durchfuehren koennen, zb: falls du dich mal wo vertippen solltest und es unabsichtlich veraenderst bekommst einen Fehler beim kompilieren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896489</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896489</guid><dc:creator><![CDATA[leo aka qsch]]></dc:creator><pubDate>Wed, 19 Oct 2005 19:03:14 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 19:10:41 GMT]]></title><description><![CDATA[<p>warum haste in MyListElement denn MyList als friend deklariert, wo sowieso alle member öffentlich sind?</p>
<p>wenn MyList schon friend ist, sollten alle pointer schon private sein.<br />
(is auch besserer stil.)</p>
<p>das &quot;this-&gt;&quot; vor dem initialisieren kannst du dir eigentlich sparen, brauchst du nicht. ausser bei element, da muss der member dann natürlich anders heissen als das ctor-argument..</p>
<p>ganz gut find ich (das sehen andre wahrscheinlich wieder anders..) klassen-member immer mit unterstrich zu benennen, also zb: _element<br />
dann reicht:</p>
<pre><code class="language-cpp">template &lt;class T&gt; 
MyListElement&lt;T&gt;::MyListElement( T* element ) 
{ 
   _element = element; 
   _next = 0; 
   _prev = 0; 
}
</code></pre>
<p>insgesamt gibts, glaub ich, schnuckligere wege solche listen zu implementieren, aber wenn du dir das alles selbst aus den fingern gesaugt hast, ist das schon ok! <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="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/896493</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896493</guid><dc:creator><![CDATA[prokaion]]></dc:creator><pubDate>Wed, 19 Oct 2005 19:10:41 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 20:43:51 GMT]]></title><description><![CDATA[<p>Das die MyListElement pointer private sind, war auch vorgesehn.<br />
ich hab das wohl auch beim debugen vergessen..</p>
<p>wann ich this pointer verwenden muss, weiß ich selber. unser java lehrer hat gesagt, dass er this pointer immer verwendet<br />
(wegen besserer uebersichtlichkeit -&gt; bei this weiß er immer, dass sie vom obj. sind). ich hab das aber nicht konsequent durchgesetzt..<br />
ist glaub ich auch das gleiche wie bei _vari oder m_vari..<br />
this-&gt; hat den vorteil, dass dann automatisch eine dropdownliste mit erreichbaren elementen kommt (im vc von micisoft kommt sie glaub ich immer -&gt; find ich besser)<br />
oder kann man das auch im kdev einrichten (und ich weiß nicht wo) ?</p>
<p>da zeigt sich wieder, dass ich das ganze noch nicht im blut hab..</p>
<p>danke..morgen kommt die ueberarbeitete vers.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10293">@prokaion</a><br />
ich hab es anfangs teilweise hier abgeschaut (aber selber ausprogrammiert und eigentlich ist nicht mehr viel vom uhrspruenglichen uebrig):<br />
<a href="http://www.mathematik.uni-marburg.de/~cpp/templates/index.html" rel="nofollow">http://www.mathematik.uni-marburg.de/~cpp/templates/index.html</a><br />
[auf klassentemplates und dann paar mal weiter klicken]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896573</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Wed, 19 Oct 2005 20:43:51 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 20:56:29 GMT]]></title><description><![CDATA[<p>.filmor schrieb:</p>
<blockquote>
<p>NULL ist C, in C++ _sollte_ man 0 nehmen.</p>
</blockquote>
<p>Das ist ja wohl geschmackssache. selbst wenn NULL als 0 definiert ist, kann man somit kennzeichnen, dass der zeiger ein nullzeiger ist. Natürlich ist das bei einer einfachen zuweisung nicht ausschalggebend, da versteht man beides, aber bei einer funktion setBuffer(NULL,0) weis man viel eher, was sache ist. Aber da bewegt man sich sehr im Bereich der persönlichen Code conventionen, und da macht eh jeder das, was er als das beste erachtet. Ich bin zumindest sehr gut damit gefahren, nullzeiger mit NULL zu bezeichnen, damit ich einen zeiger sehr schnell von anderen parametern(die zufälligerweise auch 0 sind) unterscheiden kann, wenn ich den Code überfliege.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896582</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896582</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Wed, 19 Oct 2005 20:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Wed, 19 Oct 2005 22:15:40 GMT]]></title><description><![CDATA[<p>- augenkrebs vermeiden (kommentare und das da =&gt; // #######################....)<br />
- initialisierungsliste nutzen<br />
- zeiger müssen im destruktor nicht auf 0 gesetzt werden, weil es sie dann sowieso nicht mehr gibt<br />
- präfix-operator nehmen<br />
- anstatt die kommentare in die funktion zu schreiben, lieber oben drüber, so wie bei doxygen. das ist ordentlicher und man kann doxygen verwenden <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>
<p>für NULL vs &quot;0&quot; =&gt; FAQ</p>
<blockquote>
<pre><code class="language-cpp">setBuffer(NULL,0)
</code></pre>
</blockquote>
<p>sieht man sowieso nur bei c-wrappern, weshalb das meiner meinung nach kein argument ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896630</guid><dc:creator><![CDATA[terraner]]></dc:creator><pubDate>Wed, 19 Oct 2005 22:15:40 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 05:15:14 GMT]]></title><description><![CDATA[<p>terraner schrieb:</p>
<blockquote>
<p>für NULL vs &quot;0&quot; =&gt; FAQ</p>
<blockquote>
<pre><code class="language-cpp">setBuffer(NULL,0)
</code></pre>
</blockquote>
<p>sieht man sowieso nur bei c-wrappern, weshalb das meiner meinung nach kein argument ist.</p>
</blockquote>
<p>std::cout.rdbuf()-&gt;pubsetbuf(NULL,0); schaltet buffering in der console aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896678</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Thu, 20 Oct 2005 05:15:14 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 06:41:46 GMT]]></title><description><![CDATA[<p>otze schrieb:</p>
<blockquote>
<p>Ich bin zumindest sehr gut damit gefahren, nullzeiger mit NULL zu bezeichnen, damit ich einen zeiger sehr schnell von anderen parametern(die zufälligerweise auch 0 sind) unterscheiden kann, wenn ich den Code überfliege.</p>
</blockquote>
<p>Man darf sich dann nur nicht wundern, wenn bei einem NULL-Parameter die Überladung für int aufgerufen wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/896716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/896716</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Thu, 20 Oct 2005 06:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 18:13:55 GMT]]></title><description><![CDATA[<p>otze schrieb:</p>
<blockquote>
<p>std::cout.rdbuf()-&gt;pubsetbuf(NULL,0); schaltet buffering in der console aus.</p>
</blockquote>
<p>na da sind ja ganze ~6 methoden in der iostream-lib, die zeiger übernehmen. ein bisschen wenig im vergleich zum rest der stl. aber wenn du mir vielleicht noch die name einiger anderer libs nennen könntest, die null-pointer akzeptieren, überdenke ich nochmal meine meinung. ausgenommen sind natürlich funkionen wie z.b. std::time, da die ursprünglich aus c sind und man in c das mit überladung und standard-argumenten arbeiten könnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897103</guid><dc:creator><![CDATA[terraner]]></dc:creator><pubDate>Thu, 20 Oct 2005 18:13:55 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 18:20:58 GMT]]></title><description><![CDATA[<p>terraner schrieb:</p>
<blockquote>
<p>otze schrieb:</p>
<blockquote>
<p>std::cout.rdbuf()-&gt;pubsetbuf(NULL,0); schaltet buffering in der console aus.</p>
</blockquote>
<p>na da sind ja ganze ~6 methoden in der iostream-lib, die zeiger übernehmen. ein bisschen wenig im vergleich zum rest der stl. aber wenn du mir vielleicht noch die name einiger anderer libs nennen könntest, die null-pointer akzeptieren, überdenke ich nochmal meine meinung. ausgenommen sind natürlich funkionen wie z.b. std::time, da die ursprünglich aus c sind und man in c das mit überladung und standard-argumenten arbeiten könnte.</p>
</blockquote>
<p>Irrlicht</p>
<p>(z.b.: irr::createDevice(...,NULL); //NULL bezieht sich hier auf den EventReceiver)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897108</guid><dc:creator><![CDATA[roan312]]></dc:creator><pubDate>Thu, 20 Oct 2005 18:20:58 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 18:44:44 GMT]]></title><description><![CDATA[<p>terraner schrieb:</p>
<blockquote>
<p>- augenkrebs vermeiden (kommentare und das da =&gt; // #######################....)<br />
- initialisierungsliste nutzen<br />
- zeiger müssen im destruktor nicht auf 0 gesetzt werden, weil es sie dann sowieso nicht mehr gibt<br />
- präfix-operator nehmen<br />
- anstatt die kommentare in die funktion zu schreiben, lieber oben drüber, so wie bei doxygen. das ist ordentlicher und man kann doxygen verwenden <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>
</blockquote>
<p>@augenkrebs<br />
ok, werd die kommentare ein bisschen umstellen..<br />
@init. liste / zeiger im destruktor<br />
hab ich geaendert<br />
@praefix operator<br />
was meinst du da genau?<br />
@komentare wie bei doxygen<br />
hm, meiner meinung sollten die komentare die funktionsweise erklaeren..<br />
deshalb hab ich sie auch in die funktionen geschrieben.<br />
werd sie aber noch ueberarbeiten..<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9784">@NULL</a> vs 0<br />
mir gefaellt eigentlich NULL besser. hat NULL geschwindigkeitsnachteile etc?<br />
wird es wirklich so verachtet? (es ist ja kein prob alles auf 0 umzustellen..)</p>
<p>mfg aMan</p>
<p>die neue vers. kommt auch gleich..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897130</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Thu, 20 Oct 2005 18:44:44 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 19:09:26 GMT]]></title><description><![CDATA[<p>verbesserte version:</p>
<p>ich hab auch die deleteCurrentElement() methode umgebaut.<br />
welche ist den beser (alte/neue)?</p>
<p>@die ///####/// komentare<br />
die trennen den haeder von der implementierung. ich habe jetzt nur noch eine zeile.<br />
warum kann man eigentlich bei templates den code nicht von der implementierung trennen?</p>
<p>mylistelement.h</p>
<pre><code class="language-cpp">#ifndef MYLISTELEMENT_H
#define MYLISTELEMENT_H

// #include &quot;mylist.h&quot;
template &lt;class T&gt;
class MyList;

/**
@author Adam Celarek
*/

template &lt;class T&gt;
class MyListElement
{
   private:
      MyListElement(T* element);
      ~MyListElement();

      MyListElement* m_next;
      MyListElement* m_prev;
      T* m_element;

      friend class MyList&lt;T&gt;;
};

///########################################################################################///

///#### con- / destructor
template &lt;class T&gt;
MyListElement&lt;T&gt;::MyListElement(T* element) : m_element(element)
{
   m_next = NULL;
   m_prev = NULL;
}

template &lt;class T&gt;
MyListElement&lt;T&gt;::~MyListElement()
{
   delete m_element;
}

#endif
</code></pre>
<p>mylist.h</p>
<pre><code class="language-cpp">#ifndef MYLIST_H
#define MYLIST_H

#include &quot;mylistelement.h&quot;

/**
@author Adam Celarek
*/

template &lt;class T&gt;
class MyList
{
   public:
      MyList();
      ~MyList();
      void append(T* element);              // appends T* element and resets the next() function
      bool deleteCurrentElement();          // delete previously returned_element. so a current() after a
                                            // deleteCurrentElement() will always give a NULL
                                            // returns false if returned_element is NULL or if list_size is 0
      unsigned int size() const;
      T* next();                            // returns next_element; if the last element of the list
                                            // have been already returned, the function returns NULL
      T* current() const;
      T* first();                           // returns first elem, and resets the next() function
   private:
      MyListElement&lt;T&gt;* m_first_element;
      MyListElement&lt;T&gt;* m_returned_element; // this element may be deleted / was returned by next (if not, then it's NULL)
      MyListElement&lt;T&gt;* m_next_element;     // next element, that will be returned
      MyListElement&lt;T&gt;* m_last_element;
      unsigned int m_list_size;
};

///########################################################################################///

///####    con/de-tructors    ####
template &lt;class T&gt;
MyList&lt;T&gt;::MyList()
{
   m_first_element=NULL;
   m_returned_element=NULL;
   m_next_element=m_first_element;
   m_list_size=0;
}
template &lt;class T&gt;
MyList&lt;T&gt;::~MyList()
{
   MyListElement&lt;T&gt;* current_element;
   current_element = m_first_element;
   while (current_element)   // deletes the whole list; beginning at the first element
   {
      m_first_element = current_element-&gt;m_next;
      delete current_element;
      current_element=m_first_element;
   }
}

///####    acces    ####

/*!
    \fn MyList::append()
 */
template &lt;class T&gt;
void MyList&lt;T&gt;::append(T* element)
{
   // 2 cases:
   // 1. there are no elements in the list
   // 2. there are elements in the list

   MyListElement&lt;T&gt;* new_element = new MyListElement&lt;T&gt;(element);

   if (m_list_size == 0)   // case 1: no elements in the list
   {
      m_first_element=new_element;
      m_last_element=new_element;
   }
   else   // case 2: the new element will be appended to the end of the list
   {
      m_last_element-&gt;m_next = new_element;
      new_element-&gt;m_prev = m_last_element;
      m_last_element = new_element;
   }

   first();                               // resets the next() function
   m_list_size++;
}

/*!
    \fn MyList::deleteCurrentElement()
 */
template &lt;class T&gt;
bool MyList&lt;T&gt;::deleteCurrentElement()
{
   // no elements
   if (m_returned_element==NULL || m_list_size==0)
   {
      return false;
   }

   // changing pointers
   if (m_returned_element-&gt;m_next != NULL)
      m_returned_element-&gt;m_next-&gt;m_prev = m_returned_element-&gt;m_prev;
   if (m_returned_element-&gt;m_prev != NULL)
      m_returned_element-&gt;m_prev-&gt;m_next = m_returned_element-&gt;m_next;

   // if deleteting the first element
   if (m_returned_element == m_first_element)
   {
      m_first_element = m_next_element;
   }

   // if deleteting the last element
   if (m_returned_element == m_last_element)
   {
      m_last_element = m_returned_element-&gt;m_prev;
   }

   delete m_returned_element;
   m_list_size--;
   return true;
}

/*!
    \fn MyList::first()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::first()
{
   m_returned_element = m_first_element;
   m_next_element = m_first_element-&gt;m_next;

   if (m_returned_element != NULL)
      return m_returned_element-&gt;m_element;
   else return NULL;
}

/*!
    \fn MyList::next()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::next()
{
   if (m_next_element==NULL)
   {
      m_returned_element = NULL;           // the m_next_element is only NULL,
      return NULL;                         // if the last position was already returned.
   }                                       // it's even a check, so that the else clause can't make a segmentation fault
   else
   {
      m_returned_element = m_next_element;
      m_next_element = m_returned_element-&gt;m_next;
      return m_returned_element-&gt;m_element;
   }
}

/*!
    \fn MyList::current()
 */
template &lt;class T&gt;
T* MyList&lt;T&gt;::current() const
{
   if(m_returned_element!=NULL)
      return m_returned_element-&gt;m_element;
   else
      return NULL;
}

///####   properties    ####
/*!
    \fn MyList::size()
 */
template &lt;class T&gt;
unsigned int MyList&lt;T&gt;::size() const
{
    return m_list_size;
}

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/897148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897148</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Thu, 20 Oct 2005 19:09:26 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 20:09:50 GMT]]></title><description><![CDATA[<p>aMan schrieb:</p>
<blockquote>
<p>@praefix operator<br />
was meinst du da genau?</p>
</blockquote>
<pre><code class="language-cpp">int i = 0;
cout &lt;&lt; &quot;1: &quot; &lt;&lt; i &lt;&lt; '\n';
cout &lt;&lt; &quot;2: &quot; &lt;&lt; ++i &lt;&lt; &quot;, &quot; &lt;&lt; i &lt;&lt; '\n'; // präfix
cout &lt;&lt; &quot;3: &quot; &lt;&lt; i++ &lt;&lt; &quot;, &quot; &lt;&lt; i &lt;&lt; '\n'; // postfix
</code></pre>
<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-123172-and-highlight-is-.html" rel="nofollow">noch ein thread dazu</a></p>
<blockquote>
<p>hat NULL geschwindigkeitsnachteile etc?<br />
wird es wirklich so verachtet? (es ist ja kein prob alles auf 0 umzustellen..)</p>
</blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/26836">@topic</a> speed: nein, weil es ein macro ist.<br />
nein, imo ist es zum großen teil geschmackssache, ob man es einsetzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897188</guid><dc:creator><![CDATA[terraner]]></dc:creator><pubDate>Thu, 20 Oct 2005 20:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 20:17:13 GMT]]></title><description><![CDATA[<p>ok, danke..</p>
<p>@praefix operator<br />
was das ist weiß ich schon, ich weiß nur nicht, wo ich ihn verwenden sollte..</p>
<p>mfg aman..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897194</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Thu, 20 Oct 2005 20:17:13 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 20:31:45 GMT]]></title><description><![CDATA[<p>aMan schrieb:</p>
<blockquote>
<p>was das ist weiß ich schon, ich weiß nur nicht, wo ich ihn verwenden sollte..</p>
</blockquote>
<p>Da, wo du m_list_size rauf- und runterzählst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897211</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Thu, 20 Oct 2005 20:31:45 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Thu, 20 Oct 2005 20:40:24 GMT]]></title><description><![CDATA[<p>hmm..<br />
warum ist da ein praefix oper. besser als ein post oper.?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897220</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Thu, 20 Oct 2005 20:40:24 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 04:38:31 GMT]]></title><description><![CDATA[<p>aMan schrieb:</p>
<blockquote>
<p>warum ist da ein praefix oper. besser als ein post oper.?</p>
</blockquote>
<p>In dem Fall ist es egal, weil du den Rückgabewert nicht auswertest und es sich um einen eingebauten Datentyp handelt.</p>
<p>Aber es kann nicht schaden, wenn du dir angewöhnst, die Präfixversion zu benutzen, wenn es egal ist, damit du es automatisch richtig machst, wenn es nicht egal ist. Sieh einfach die Präfixversion als den Normalfall an und benutz die Postfixversion nur dort, wo du wirklich den &quot;alten&quot; Wert als Rückgabewert brauchst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897293</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 21 Oct 2005 04:38:31 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 04:56:33 GMT]]></title><description><![CDATA[<p>MFK schrieb:</p>
<blockquote>
<p>otze schrieb:</p>
<blockquote>
<p>Ich bin zumindest sehr gut damit gefahren, nullzeiger mit NULL zu bezeichnen, damit ich einen zeiger sehr schnell von anderen parametern(die zufälligerweise auch 0 sind) unterscheiden kann, wenn ich den Code überfliege.</p>
</blockquote>
<p>Man darf sich dann nur nicht wundern, wenn bei einem NULL-Parameter die Überladung für int aufgerufen wird.</p>
</blockquote>
<p>sicher. nur gut, dass es keinen sinnvollen Fall gibt, bei dem man als argument entweder einen int oder einen null-zeiger erwarten kann <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/897295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897295</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Fri, 21 Oct 2005 04:56:33 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 05:26:27 GMT]]></title><description><![CDATA[<p>otze schrieb:</p>
<blockquote>
<p>nur gut, dass es keinen sinnvollen Fall gibt, bei dem man als argument entweder einen int oder einen null-zeiger erwarten kann <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>
</blockquote>
<p>Nur gut, dass jeder Programmierer auf der Welt nur sinnvolle Überladungen erstellt <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/897300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897300</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 21 Oct 2005 05:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 06:39:50 GMT]]></title><description><![CDATA[<p>aMan schrieb:</p>
<blockquote>
<p>warum kann man eigentlich bei templates den code nicht von der implementierung trennen?</p>
</blockquote>
<p>Weil der Compiler bei der Verarbeitung des Templates wissen muß, (a) wie das Template aufgebaut ist (Quelltext) und (b) mit welchen Typen es verwendet wird (instantiierung). Die Informationen hat er nur zusammen, wenn du den Code direkt in dein Programm inkludierst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897346</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 21 Oct 2005 06:39:50 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 09:29:39 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>aMan schrieb:</p>
<blockquote>
<p>warum kann man eigentlich bei templates den code nicht von der implementierung trennen?</p>
</blockquote>
<p>Weil der Compiler bei der Verarbeitung des Templates wissen muß, (a) wie das Template aufgebaut ist (Quelltext) und (b) mit welchen Typen es verwendet wird (instantiierung). Die Informationen hat er nur zusammen, wenn du den Code direkt in dein Programm inkludierst.</p>
</blockquote>
<p>Könnte man sich die Codeguards ansonsten nicht auch sparen?<br />
Oder gibt es noch andere solche fälle, wo Definitionen im Header stehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897524</guid><dc:creator><![CDATA[roan312]]></dc:creator><pubDate>Fri, 21 Oct 2005 09:29:39 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 14:24:36 GMT]]></title><description><![CDATA[<p>roan312 schrieb:</p>
<blockquote>
<p>Könnte man sich die Codeguards ansonsten nicht auch sparen?<br />
Oder gibt es noch andere solche fälle, wo Definitionen im Header stehen?</p>
</blockquote>
<p>Includeguards (ich nehme an, dass du die meinst) haben mit Definitionen in Headerdateien nichts zu tun. Include-Guards verhindern das mehrfache Einbinden einer Headerdatei in <strong>einer</strong> Übersetzungseinheit. Damit lassen sich z.B. unendliche Includerekursionen verhindern. Definitionen in Headerdateien können nur zwischen mehreren Übersetzungseinheiten Probleme machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897863</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 21 Oct 2005 14:24:36 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 15:41:11 GMT]]></title><description><![CDATA[<p>MFK schrieb:</p>
<blockquote>
<p>roan312 schrieb:</p>
<blockquote>
<p>Könnte man sich die Codeguards ansonsten nicht auch sparen?<br />
Oder gibt es noch andere solche fälle, wo Definitionen im Header stehen?</p>
</blockquote>
<p>Includeguards (ich nehme an, dass du die meinst) haben mit Definitionen in Headerdateien nichts zu tun. Include-Guards verhindern das mehrfache Einbinden einer Headerdatei in <strong>einer</strong> Übersetzungseinheit. Damit lassen sich z.B. unendliche Includerekursionen verhindern. Definitionen in Headerdateien können nur zwischen mehreren Übersetzungseinheiten Probleme machen.</p>
</blockquote>
<p>Das mit den Includerekursionen stimmt, daran hab ich nicht gedacht,<br />
aber mehrfach Definitionen innerhalb <strong>einer</strong> Übersetzungseinheit machen auch schwierigkeiten.</p>
<p>EDIT:</p>
<pre><code>class foo
{};

class foo
{};
</code></pre>
<p>Redifinition if class foo...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897958</guid><dc:creator><![CDATA[roan312]]></dc:creator><pubDate>Fri, 21 Oct 2005 15:41:11 GMT</pubDate></item><item><title><![CDATA[Reply to code bewerten on Fri, 21 Oct 2005 15:49:03 GMT]]></title><description><![CDATA[<p>ok, danke leuds..</p>
<p>koennt ihr mir noch sagen, welche der beiden (alt und neu) deleteCurrentElement() methoden besser ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/897995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/897995</guid><dc:creator><![CDATA[aMan]]></dc:creator><pubDate>Fri, 21 Oct 2005 15:49:03 GMT</pubDate></item></channel></rss>