<?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[verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage)]]></title><description><![CDATA[<p>Hallo liebe Community.<br />
Ich bin noch neu in C++ und habe vorher PHP gelernt.<br />
In PHP kann man ein ein Array verschiedene Variablen Typen speichern.<br />
Z.B.</p>
<pre><code>$beispiel = array();
$beispiel[1] = &quot;string&quot;;
$beispiel[2] = 32;
$beispiel[3] = true;
//usw...
</code></pre>
<p>In C++ muss man aber angeben, welche Variablen in einem Array gespeichert werden und man kann nicht verschiedene Typen gleichzeitig speichern.<br />
Wie macht ihr das denn, wenn ihr in so eine Situation kommt, in der ihr mehrere unterschiedliche Variablen Typen in ein Array schreiben müsst, oder wenn es bei einer Funktion verschiedene Rückgabe Typen geben soll?</p>
<p>Grüße,<br />
Steffie</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/174184/verschiedene-variablen-typen-in-arrays-funktionen-anfängerfrage</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 14:41:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174184.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Feb 2007 18:40:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 18:41:09 GMT]]></title><description><![CDATA[<p>Hallo liebe Community.<br />
Ich bin noch neu in C++ und habe vorher PHP gelernt.<br />
In PHP kann man ein ein Array verschiedene Variablen Typen speichern.<br />
Z.B.</p>
<pre><code>$beispiel = array();
$beispiel[1] = &quot;string&quot;;
$beispiel[2] = 32;
$beispiel[3] = true;
//usw...
</code></pre>
<p>In C++ muss man aber angeben, welche Variablen in einem Array gespeichert werden und man kann nicht verschiedene Typen gleichzeitig speichern.<br />
Wie macht ihr das denn, wenn ihr in so eine Situation kommt, in der ihr mehrere unterschiedliche Variablen Typen in ein Array schreiben müsst, oder wenn es bei einer Funktion verschiedene Rückgabe Typen geben soll?</p>
<p>Grüße,<br />
Steffie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234272</guid><dc:creator><![CDATA[Steffie]]></dc:creator><pubDate>Fri, 23 Feb 2007 18:41:09 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 18:48:48 GMT]]></title><description><![CDATA[<p>Also Funktionen würde ich einfach überladen.</p>
<p>Sieht ungefähr so aus:</p>
<pre><code class="language-cpp">int funktion1 (int a);
string funktion1 (string blabla);
</code></pre>
<p>Jetzt unterscheidet der Compiler anhand der Argumente, mit der du dir Funktion aufrufst, welche er nehmen muss.<br />
Weiß nicht, ob du das so meintest...</p>
<p>Beim Array fällt mir jetzt gerade keine Möglichkeit ein.<br />
Allerdings auch keine Situation, in der du das brauchen könntest...<br />
Wenn du wirklich sowas brauchst, konvertierst du sonst einfach die Typen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234278</guid><dc:creator><![CDATA[Sinthoras]]></dc:creator><pubDate>Fri, 23 Feb 2007 18:48:48 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 19:31:32 GMT]]></title><description><![CDATA[<p>Sinthoras schrieb:</p>
<blockquote>
<p>Also Funktionen würde ich einfach überladen.</p>
<p>Sieht ungefähr so aus:</p>
<pre><code class="language-cpp">int funktion1 (int a);
string funktion1 (string blabla);
</code></pre>
<p>Jetzt unterscheidet der Compiler anhand der Argumente, mit der du dir Funktion aufrufst, welche er nehmen muss.<br />
Weiß nicht, ob du das so meintest...</p>
</blockquote>
<p>Ich dachte eher an so etwas:</p>
<pre><code>int funktion1(int a)
{
  if(a == 1) return &quot;abc&quot;;
  else return 123;
}
</code></pre>
<p>Dieser Code funktioniert nicht, weil die Funktion keinen String zurückgeben kann. So meinte ich das.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234301</guid><dc:creator><![CDATA[Steffie]]></dc:creator><pubDate>Fri, 23 Feb 2007 19:31:32 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 19:52:55 GMT]]></title><description><![CDATA[<p>Steffie schrieb:</p>
<blockquote>
<p>Sinthoras schrieb:</p>
<blockquote>
<p>Also Funktionen würde ich einfach überladen.</p>
<p>Sieht ungefähr so aus:</p>
<pre><code class="language-cpp">int funktion1 (int a);
string funktion1 (string blabla);
</code></pre>
<p>Jetzt unterscheidet der Compiler anhand der Argumente, mit der du dir Funktion aufrufst, welche er nehmen muss.<br />
Weiß nicht, ob du das so meintest...</p>
</blockquote>
<p>Ich dachte eher an so etwas:</p>
<pre><code>int funktion1(int a)
{
  if(a == 1) return &quot;abc&quot;;
  else return 123;
}
</code></pre>
<p>Dieser Code funktioniert nicht, weil die Funktion keinen String zurückgeben kann. So meinte ich das.</p>
</blockquote>
<p>du könntest einfach statt abc 456 zurückgeben und dann außerhalb der funktion 'umwandeln bsbw.:</p>
<pre><code class="language-cpp">func{
      int* bla = 456
return bla;}

if(bla == 456) {
    string blabla = &quot;abc&quot;;}
delete bla;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1234307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234307</guid><dc:creator><![CDATA[Raxtor]]></dc:creator><pubDate>Fri, 23 Feb 2007 19:52:55 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 19:45:29 GMT]]></title><description><![CDATA[<p>Kommt dann darauf an, wofür du das brauchst.</p>
<p>Wenn du's z.B. einfach nur für die Ausgabe brauchst, nimmst du halt immer string.<br />
Ich denke mal nicht, dass du das willst, also würde ich folgendes machen:</p>
<pre><code class="language-cpp">int iwert;
string swert;
//...
void funktion1 (int a, int &amp;intwert, string &amp;stringwert)
{
if (a == 1) intwert = 123;
else stringwert = &quot;abc&quot;;
}
</code></pre>
<p>Dann musst du's nur halt mit beiden Möglichkeiten aufrufen.<br />
Also entweder</p>
<pre><code class="language-cpp">iwert = funktion1 (1, &amp;iwert, &amp;swert)
</code></pre>
<p>...oder...</p>
<pre><code class="language-cpp">swert = funktion1 (0, &amp;iwert, &amp;swert)
</code></pre>
<p>Wofür man das dann benutzen kann, ist mir aber immernoch schleierhaft...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234309</guid><dc:creator><![CDATA[Sinthoras]]></dc:creator><pubDate>Fri, 23 Feb 2007 19:45:29 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 20:07:59 GMT]]></title><description><![CDATA[<p>oder boost::any</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234317</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Fri, 23 Feb 2007 20:07:59 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 22:11:54 GMT]]></title><description><![CDATA[<p>Maxi schrieb:</p>
<blockquote>
<p>oder boost::any</p>
</blockquote>
<p>Ja das gefällt mir ganz gut.<br />
Hat das auch irgentwelche Haken?<br />
Alles in C++ hat nämlich irgentwelche Haken, wenn es bequem sein soll. (So kommt es mir zumindest vor o.O)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234387</guid><dc:creator><![CDATA[Steffie]]></dc:creator><pubDate>Fri, 23 Feb 2007 22:11:54 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 23:44:57 GMT]]></title><description><![CDATA[<p>Es ist kein Standard (soweit ich weiß).</p>
<p>Sonst ist mir keiner bekannt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234424</guid><dc:creator><![CDATA[Sinthoras]]></dc:creator><pubDate>Fri, 23 Feb 2007 23:44:57 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 23:46:33 GMT]]></title><description><![CDATA[<p>Weil du wohl standar<strong>t</strong> und nicht standar<strong>d</strong> geschrieben hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234428</guid><dc:creator><![CDATA[Steffie]]></dc:creator><pubDate>Fri, 23 Feb 2007 23:46:33 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Fri, 23 Feb 2007 23:48:50 GMT]]></title><description><![CDATA[<p>Danke, ich hab's dann auch selbst bemerkt <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/1234431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234431</guid><dc:creator><![CDATA[Sinthoras]]></dc:creator><pubDate>Fri, 23 Feb 2007 23:48:50 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen Typen in Arrays&#x2F;Funktionen (Anfängerfrage) on Sat, 24 Feb 2007 02:14:21 GMT]]></title><description><![CDATA[<p>Wenn es bequem sein soll, dann programmiere Python.<br />
C++ ist alles nur nicht &quot;bequem&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1234470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1234470</guid><dc:creator><![CDATA[Die_Gute_Fee]]></dc:creator><pubDate>Sat, 24 Feb 2007 02:14:21 GMT</pubDate></item></channel></rss>