<?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[Funktions verhalten?]]></title><description><![CDATA[<p>Guten abend,<br />
ich möchte eine Funktion schreiben, welche sich je nachdem ob der parameter ein array ist oder nicht anders verhält. In anderen Worten möchte ich eine möklichkeit wie ich abfragen kann ob eine Variable ein Array ist oder nicht. String ist der datentyp, dieser bleibt auch immer gleich.<br />
Wie kriege ich sowas hin?</p>
<p>Danke schonmal im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/266623/funktions-verhalten</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 04:16:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/266623.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 May 2010 18:39:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 18:39:19 GMT]]></title><description><![CDATA[<p>Guten abend,<br />
ich möchte eine Funktion schreiben, welche sich je nachdem ob der parameter ein array ist oder nicht anders verhält. In anderen Worten möchte ich eine möklichkeit wie ich abfragen kann ob eine Variable ein Array ist oder nicht. String ist der datentyp, dieser bleibt auch immer gleich.<br />
Wie kriege ich sowas hin?</p>
<p>Danke schonmal im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895921</guid><dc:creator><![CDATA[TheJoker]]></dc:creator><pubDate>Tue, 11 May 2010 18:39:19 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 18:42:27 GMT]]></title><description><![CDATA[<p>TheJoker schrieb:</p>
<blockquote>
<p>Guten abend,<br />
ich möchte eine Funktion schreiben, welche sich je nachdem ob der parameter ein array ist oder nicht anders verhält. In anderen Worten möchte ich eine möklichkeit wie ich abfragen kann ob eine Variable ein Array ist oder nicht. String ist der datentyp, dieser bleibt auch immer gleich.<br />
Wie kriege ich sowas hin?</p>
<p>Danke schonmal im voraus</p>
</blockquote>
<p>Eine Funktionsüberladung bzw. Templates könnten das schön lösen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895925</guid><dc:creator><![CDATA[hjkhjk]]></dc:creator><pubDate>Tue, 11 May 2010 18:42:27 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 18:55:06 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;typename T&gt;
void GetVar(const T &amp;var)
{
    std::cout&lt;&lt; typeid(var).name() &lt;&lt;std::endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1895926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895926</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Tue, 11 May 2010 18:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 18:43:26 GMT]]></title><description><![CDATA[<p>11 Sekunden, wie l33t-mäßig <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1895927</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895927</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Tue, 11 May 2010 18:43:26 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 18:44:43 GMT]]></title><description><![CDATA[<p>Das machst du indem du die Funktion überlädst:</p>
<pre><code class="language-cpp">void foo(Datentyp bar)
{
   // Normalfall
}

void foo(Datentyp* bar);  
{
   // Parameter war ein Array
}
</code></pre>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>11 Sekunden, wie l33t-mäßig <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>
</blockquote>
<p>Mach dir nichts draus, ich war noch langsamer <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1895928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895928</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 11 May 2010 18:44:43 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 19:27:10 GMT]]></title><description><![CDATA[<p>Vielen dank für die schnellen antworten.<br />
eine frage habe ich jedoch..<br />
Wieso ist hier ein Stern zur differenzierung des falles verwedet worden?</p>
<pre><code class="language-cpp">void foo(Datentyp bar)
{
   // Normalfall
}

void foo(Datentyp* bar);  
{
   // Parameter war ein Array
}
</code></pre>
<p>muss das nicht so ausehen?</p>
<pre><code class="language-cpp">void foo(Datentyp bar)
{
   // Normalfall
}

void foo(Datentyp bar[]);  
{
   // Parameter war ein Array
}
</code></pre>
<p>ich bin nicht mehr ganz so neu in c++ und weiß das Sterne im normallfall einen Zeiger einleiten... deswegen verschtehe ich das nicht ganz...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895942</guid><dc:creator><![CDATA[TheJoker]]></dc:creator><pubDate>Tue, 11 May 2010 19:27:10 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 20:03:19 GMT]]></title><description><![CDATA[<p>Arrays sind quasi nichts anderes als eine Art mehrerer Werte, die im Speicher hintereinander liegen.<br />
Deshalb ist folgendes Beispiel valid und erklärt, warum das funktioniert:</p>
<pre><code class="language-cpp">int array[] = { 8, 9, 10, 11, 12 };

// &quot;normaler&quot; Zugriff
int x = array[0]; // 8
int x = array[1]; // 9
int x = array[2]; // 10
int x = array[3]; // 11
int x = array[4]; // 12

// Pointer-Zugriff (nicht verwenden wenn normaler Zugriff verfügbar!)
int x = *(array + 0) // 8
int x = *(array + 1) // 9
int x = *(array + 2) // 10
int x = *(array + 3) // 11
int x = *(array + 4) // 12

// (array + 0) ist also = array, d.H. array ist der Beginn der Speicherstelle im Speicher (= Pointer auf das 0. Element)
// Das ist auch der Grund warum man die Länge von Arrays in C manuell mitgeben muss, denn...
// array[5] oder *(array + 5) würden vermutlich crashen bzw. undefiniertes Verhalten bzw. komische Werte aufrufen
</code></pre>
<p>Ich hoffe ich liege mit meiner Erklärung richtig!</p>
<p>Edit: Bei <code>char*</code> -Arrays wird meistens nicht die Anzahl der Elemente (= Länge des Strings) per Parameter mitgegeben, sondern das letzte Element (Zugriff via Länge des Strings) beinhaltet das Zeichen <code>'\0'</code> , was anzeigt, dass der String hier zu Ende ist. Fehlt das, so können Funktionen wie <code>std::strcpy</code> etc. crashen. Dafür gibt es dann sichere(re) Funktionen wie <code>std::strncpy</code> .</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895950</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Tue, 11 May 2010 20:03:19 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 20:02:15 GMT]]></title><description><![CDATA[<p>(array+5) ist falsch.</p>
<p>array[5] und *(array+5) sind <strong>identisch</strong>.</p>
<p>Weitere Informationen: <a href="http://c-faq.com/aryptr/index.html" rel="nofollow">http://c-faq.com/aryptr/index.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895955</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Tue, 11 May 2010 20:02:15 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 20:03:40 GMT]]></title><description><![CDATA[<p>Sorry. Meinte ich doch. Korrigiert <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>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895956</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Tue, 11 May 2010 20:03:40 GMT</pubDate></item><item><title><![CDATA[Reply to Funktions verhalten? on Tue, 11 May 2010 20:56:58 GMT]]></title><description><![CDATA[<p>theliquidwave schrieb:</p>
<blockquote>
<p>(array + 0) ist also = array, d.H. array ist der Beginn der Speicherstelle im Speicher (= Pointer auf das 0. Element)</p>
</blockquote>
<p>Genau genommen ist <code>array</code> ein Array und kein Zeiger. Jedoch können Arrays implizit in Zeiger auf das erste Element des Arrays konvertiert werden. Deshalb kann man einer Funktion, die ein <code>char*</code> nimmt, auch ein <code>char</code> -Array übergeben; oder deshalb kann man <code>+</code> oder <code>[]</code> auf Arrays anwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895975</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895975</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 11 May 2010 20:56:58 GMT</pubDate></item></channel></rss>