<?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[Globales array]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe ein folgendes problem.</p>
<p>Wollte das Programm etwas schöner gestalten und alle Funktionen in ein andere .cpp-File schreiben.</p>
<p>Doch ich habe ein Problem:<br />
In Hauptprogramm.cpp:<br />
gibts ein Array y[10] er wird dort initialieisert (double y[10])<br />
Jetzt rüfe ich eine funktion (zB. f(x)) auf, welche in funktionen.cpp geschrieben ist</p>
<p>In funktionen.cpp:<br />
Der Wert x wird übergeben an void f(double x) und dort möchte ich, dass das Array mit Werten gefüllt wird. Diese Funktionen hat eigentlich keinen Rückgabewert, da dieses globale Array einfach füllt.</p>
<p>Doch das geht leider nicht, wenn ich in Hauptprogramm.cpp die Werte wieder anzeigen will, sind sie 0, also nicht das was ich reinschreibe.</p>
<p>Kann mir jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/165888/globales-array</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 03:53:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/165888.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Nov 2006 21:17:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Globales array on Thu, 23 Nov 2006 21:17:09 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe ein folgendes problem.</p>
<p>Wollte das Programm etwas schöner gestalten und alle Funktionen in ein andere .cpp-File schreiben.</p>
<p>Doch ich habe ein Problem:<br />
In Hauptprogramm.cpp:<br />
gibts ein Array y[10] er wird dort initialieisert (double y[10])<br />
Jetzt rüfe ich eine funktion (zB. f(x)) auf, welche in funktionen.cpp geschrieben ist</p>
<p>In funktionen.cpp:<br />
Der Wert x wird übergeben an void f(double x) und dort möchte ich, dass das Array mit Werten gefüllt wird. Diese Funktionen hat eigentlich keinen Rückgabewert, da dieses globale Array einfach füllt.</p>
<p>Doch das geht leider nicht, wenn ich in Hauptprogramm.cpp die Werte wieder anzeigen will, sind sie 0, also nicht das was ich reinschreibe.</p>
<p>Kann mir jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180375</guid><dc:creator><![CDATA[Noobie..]]></dc:creator><pubDate>Thu, 23 Nov 2006 21:17:09 GMT</pubDate></item><item><title><![CDATA[Reply to Globales array on Thu, 23 Nov 2006 22:34:44 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>übergib das Array als Parameter der Funktion, am besten als Referenz.<br />
Globale variablen sind meistens schlecht, also ist die Umstellung auf jedenfall eine Verbesserung.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180413</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Thu, 23 Nov 2006 22:34:44 GMT</pubDate></item><item><title><![CDATA[Reply to Globales array on Thu, 23 Nov 2006 22:45:12 GMT]]></title><description><![CDATA[<p>Vielen dank ich probier das mal aus, mal schauen ob ich das hinkriege... sonst melde ich mich wieder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180414</guid><dc:creator><![CDATA[Noobie..]]></dc:creator><pubDate>Thu, 23 Nov 2006 22:45:12 GMT</pubDate></item><item><title><![CDATA[Reply to Globales array on Fri, 24 Nov 2006 11:56:40 GMT]]></title><description><![CDATA[<p>Sorry kann mir jemand helfen wie ganau das geht?</p>
<p>in functions.cpp geht so etwas nicht</p>
<p>void f(double x, float&amp; array[])<br />
{<br />
array[i]=12;<br />
}</p>
<p>es kommt eine Fehlermeldung und ich kanns nicht einmal komplieren.</p>
<p>Könnte jemand ein kleines Beispiel machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180644</guid><dc:creator><![CDATA[Noobie...]]></dc:creator><pubDate>Fri, 24 Nov 2006 11:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to Globales array on Fri, 24 Nov 2006 12:05:56 GMT]]></title><description><![CDATA[<p>Hallo</p>
<blockquote>
<p>es kommt eine Fehlermeldung</p>
</blockquote>
<p>Du solltest immer Fehlermeldungen und -beschreibungen mit posten.</p>
<p>Du kannst Array nicht ohne Dimensionsangabe übergeben. Wenn du ein dynamishes Array übergeben willst, must du entweder einen Pointer mitsamt Größenangabe verwenden</p>
<pre><code class="language-cpp">void f(double x, float* array, int array size)
{
array[i]=12;
} 

// Beispielanwendung
float* array = new float[20];
f(12.0, array, 20);
</code></pre>
<p>, oder besser gleich der echte C++ Weg : einen Container wie std::vector benutzen.</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
void f(double x, std::vector&lt;float&gt;&amp; array)
{
  array[i] = 12;
}

std::vector&lt;float&gt; array;
array.push_back(1234.45); // Einzelne Werte in Array ein tragen
f(12.4, array);
</code></pre>
<p>Mehr zum Thema STL-Container findest du im C++ Forum, in der C++ FAQ und in den Magazinartikeln hier im Forum.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180652</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 24 Nov 2006 12:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to Globales array on Fri, 24 Nov 2006 12:34:59 GMT]]></title><description><![CDATA[<p>Super!</p>
<p>Alles läuft jetzt prima!</p>
<p>Vielen vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1180672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1180672</guid><dc:creator><![CDATA[Noobie...]]></dc:creator><pubDate>Fri, 24 Nov 2006 12:34:59 GMT</pubDate></item><item><title><![CDATA[Reply to Globales array on Thu, 07 Dec 2006 12:47:38 GMT]]></title><description><![CDATA[<p>Ich komme wieder mit einem Problem, welches auch zum Thema gehört..</p>
<p>Würde gerne das Array 2-Dimensional machen. Doch jetzt gibts das Problem mit der Grösseneingabe als Paramter, jetzt gebe ich ja ein int ein, welches nur 1-Dimensional ist.</p>
<p>akari, kannst Du mir da wieder etwas Hilfe leisten, wäre superfroh.</p>
<p>Ich verwende die &quot;old-Skool&quot; Varianta (die erste, welche du als Beispiel gezeigt hast) und das möchte jetzt auf 2-Dimension erweitern</p>
<p>Vielen Dank im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1188308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1188308</guid><dc:creator><![CDATA[Noobie..]]></dc:creator><pubDate>Thu, 07 Dec 2006 12:47:38 GMT</pubDate></item></channel></rss>