<?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[Array Problem]]></title><description><![CDATA[<p>Huhu. Ich hab hier ne Pascal anwendung, die ich in C++ umschreiben muss. Jetzt hat der bei Pascal folgendes Array angelegt:</p>
<pre><code>CONST Z : ARRAY [-5..5] OF real = (0.00001,0.0001,0.001,0.01,0.1,
                                   1,10,100,1000,10000,100000);
</code></pre>
<p>wie ihr seht, fängt das array im minus bereich an und beinhaltet nachkommestellen. diese werden später im programm abgefragt und das ergebnis mit den entsprechenden kommastellen multipliziert oder dividiert.</p>
<p>klar kann ich ein array von 0 - 11 anlegen, dadurch würde die ganze nachkommastellen bearbeitung viel komplizierter. ist wirklich total schräg aufgebaut alles. glaubt mir.</p>
<p>nun meine frage: kann ich im c++ auch so ein array anlegen, dass im - bereich beginnt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/118097/array-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 07:12:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/118097.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Aug 2005 08:36:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Array Problem on Mon, 15 Aug 2005 08:36:56 GMT]]></title><description><![CDATA[<p>Huhu. Ich hab hier ne Pascal anwendung, die ich in C++ umschreiben muss. Jetzt hat der bei Pascal folgendes Array angelegt:</p>
<pre><code>CONST Z : ARRAY [-5..5] OF real = (0.00001,0.0001,0.001,0.01,0.1,
                                   1,10,100,1000,10000,100000);
</code></pre>
<p>wie ihr seht, fängt das array im minus bereich an und beinhaltet nachkommestellen. diese werden später im programm abgefragt und das ergebnis mit den entsprechenden kommastellen multipliziert oder dividiert.</p>
<p>klar kann ich ein array von 0 - 11 anlegen, dadurch würde die ganze nachkommastellen bearbeitung viel komplizierter. ist wirklich total schräg aufgebaut alles. glaubt mir.</p>
<p>nun meine frage: kann ich im c++ auch so ein array anlegen, dass im - bereich beginnt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852364</guid><dc:creator><![CDATA[MSS-Software]]></dc:creator><pubDate>Mon, 15 Aug 2005 08:36:56 GMT</pubDate></item><item><title><![CDATA[Reply to Array Problem on Mon, 15 Aug 2005 08:57:26 GMT]]></title><description><![CDATA[<p>Gar nicht und das ist auch gut so....</p>
<p>Schärge Pascal-Programme in schärge C++ Programme umschreiben zu wollen is schärg... :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852371</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852371</guid><dc:creator><![CDATA[Mathias]]></dc:creator><pubDate>Mon, 15 Aug 2005 08:57:26 GMT</pubDate></item><item><title><![CDATA[Reply to Array Problem on Mon, 15 Aug 2005 09:06:05 GMT]]></title><description><![CDATA[<p>Schreib dir eine statische Funktion, die dir anhand eines Parameters die gewünschte Stelle zurückliefert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852374</guid><dc:creator><![CDATA[Mathias]]></dc:creator><pubDate>Mon, 15 Aug 2005 09:06:05 GMT</pubDate></item><item><title><![CDATA[Reply to Array Problem on Mon, 15 Aug 2005 10:47:35 GMT]]></title><description><![CDATA[<p>Du könntest dir sowas in der Art basteln:</p>
<pre><code class="language-cpp">#include &lt;exception&gt;
#include &lt;iostream&gt;

using namespace std;

template &lt;typename T, int From, int To&gt;
class array {
public:
		T&amp; operator [](int i) {
				if (i &lt; From || i &gt; To)
						throw exception();
				return buf[i + diff];
		}

		T const&amp; operator [](int i) const {
				if (i &lt; From || i &gt; To)
						throw exception();
				return buf[i + diff];
		}		

private:
		T buf[To - From];
		enum { diff = -From }; 
};

int main() {
		array&lt;float, -5, 5&gt; arr;

		try {
			arr[-5] = 0.123;
			arr[0] = 1.45;
			arr[5] = 0.002;
			cout &lt;&lt; arr[-5] &lt;&lt; ' ' &lt;&lt; arr[0] &lt;&lt; ' ' &lt;&lt; arr[5] &lt;&lt; endl;
		} catch (...) {
				cerr &lt;&lt; &quot;out of bound&quot; &lt;&lt; endl;
		}

		return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/852442</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852442</guid><dc:creator><![CDATA[zeronull]]></dc:creator><pubDate>Mon, 15 Aug 2005 10:47:35 GMT</pubDate></item><item><title><![CDATA[Reply to Array Problem on Mon, 15 Aug 2005 12:00:47 GMT]]></title><description><![CDATA[<p>ok<br />
thx</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852493</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852493</guid><dc:creator><![CDATA[MSS-Software]]></dc:creator><pubDate>Mon, 15 Aug 2005 12:00:47 GMT</pubDate></item></channel></rss>