<?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-Grenzen werden Grundlos überschritten...]]></title><description><![CDATA[<pre><code class="language-cpp">x.Resize(x.Zeil,x.Spalt);   
 // cout &lt;&lt; setiosflags(ios::right);
  for (int i=0; i&lt;x.Zeil; i++)
    for (int j=0; j&lt;x.Spalt; j++)
  {
    s &gt;&gt; ws;
    s &gt;&gt; x.Mat[i][j];
    x.Mat[i][j] = x.Mat[i][j] / x.farbtiefe;
    s &gt;&gt; ws;
    cout &lt;&lt;&quot; (&quot;&lt;&lt;i&lt;&lt;&quot;,&quot;&lt;&lt;j&lt;&lt;&quot;)&quot;&lt;&lt; x.Mat[i][j];   
  }
  return s;
</code></pre>
<p>Das ist ein Teil aus meiner Einlese - Funktion. Ich lese dabei eine PGM Datei in die Matrix x ein.<br />
Mittels Debug Ausgaben habe ich herausgefunden, dass die Daten x.Zeil und X.Spalt (Dimension der Matrix) sauber übergeben werden. Dennoch ruft mein Programm den Eintrag (0,158) auf, obwohl die Forschleife ja offenbar nur bis x.spalt geht (in diesem Beispiel 157). Ich kann mir diesen Fehler einfach überhaupt gar nicht erklären. Hat hier vielleicht jemand ne Idee, woran es liegen könnte? Oder hatte schon mal jemand ein ähnliches Problem? NAbei der komplette wichtige Quellcode:</p>
<pre><code class="language-cpp">class GreyScale
{
  private:
    float** Mat;                          // Zeiger auf Feld fuer Matrixelemente
    int     Zeil,Spalt,farbtiefe;                        // Matrixlaenge

  public:
    GreyScale  (int m=0,int n=0);                    // Konstruktor mit Laengenangabe
    ~GreyScale () { delete[] Mat; }          // Destruktor
    GreyScale  (const GreyScale&amp;);              // Kopierkonstruktor

    float&amp; operator () (int,int);            // Matrixelement schreiben
    float  operator () (int,int) const;      // Matrixelement lesen

    GreyScale&amp; operator =  (const GreyScale&amp;);  // Zuweisung
    GreyScale&amp; operator += (const GreyScale&amp;);  // Zuweisungen mit arithm. Operation
    GreyScale&amp; operator -= (const GreyScale&amp;);
    GreyScale&amp; operator *= (float);
    GreyScale&amp; operator /= (float);

    GreyScale&amp; Resize   (int,int);                      // neue Laenge festlegen
    int     GetHeight  () const { return Zeil; }    // Zeilenanzahl
    int     GetWidth  () const { return Spalt; }    // Zeilenanzahl
    int     GetDeepth  () const { return farbtiefe; }    // Zeilenanzahl

    static void MatFehler (const char str[]);   // Fehlermeldung ausgeben

    friend GreyScale   operator +  (const GreyScale&amp;, const GreyScale&amp;); // Addition
    friend GreyScale   operator -  (const GreyScale&amp;, const GreyScale&amp;); // Subtraktion
    friend GreyScale   operator -  (const GreyScale&amp;);                // Vorzeichen

    friend GreyScale   operator *  (const GreyScale&amp;, const GreyScale&amp;); // Matrixprodukt
    friend GreyScale   operator *  (double, const GreyScale&amp;);        // Vielfache
    friend GreyScale   operator *  (const GreyScale&amp;, float);
    friend GreyScale   operator /  (const GreyScale&amp;, float);

    friend bool     operator == (const GreyScale&amp;, const GreyScale&amp;); // Vergleich
    friend bool     operator != (const GreyScale&amp;, const GreyScale&amp;);

    friend istream&amp; operator &gt;&gt; (istream&amp;, GreyScale&amp;);            // Eingabe
    friend ostream&amp; operator &lt;&lt; (ostream&amp;, const GreyScale&amp;);      // Ausgabe

};

GreyScale::GreyScale (int m,int n)
{
  if (m&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Zeilenanzahl!&quot;);
  if (n&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Spaltenanzahl!&quot;);    

  Zeil=m;
  Spalt=n;

  Mat=new float*[m];
  for(int i=0; i&lt;m; i++)
    Mat[i]=new float [n];
  if (Mat==NULL)
    MatFehler(&quot;Nicht genuegend Speicher!&quot;);

  for (int i=0; i&lt;m; i++)
    for(int j=0; j&lt;n; j++)
      Mat[i][j]=0;
}

GreyScale&amp; GreyScale::Resize (int m, int n)
{        
  delete[] Mat;      
  if (m&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Zeilenanzahl!&quot;);
  if (n&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Spaltenanzahl!&quot;);    

  Zeil=m;
  Spalt=n;

  Mat=new float*[m];
  for(int i=0; i&lt;m; i++)
    Mat[i]=new float [n];
  if (Mat==NULL)
    MatFehler(&quot;Nicht genuegend Speicher!&quot;);

  for (int i=0; i&lt;m; i++)
    for(int j=0; j&lt;n; j++)
      Mat[i][j]=0;
  return *this;    
}

istream&amp; operator &gt;&gt; (istream &amp;s, GreyScale &amp;x)
{
  char b;
  b=s.get();
  cerr &lt;&lt; b; 
  if (b != 'P') GreyScale::MatFehler(&quot;Falsches Dateiformat!&quot;);
  b=s.get();
  cerr &lt;&lt; b; 
  if (b != '2') GreyScale::MatFehler(&quot;Falsches Dateiformat!&quot;); 
  s &gt;&gt; ws;
  while( s.peek() == '#')
  {
    s.ignore( 10000, '\n');  // ignore characters until line end
    s &gt;&gt; std::ws;            // eat whitespaces
  }
  s &gt;&gt; x.Spalt;
  cerr &lt;&lt; x.Spalt;
  s &gt;&gt; x.Zeil; s &gt;&gt; ws;
  cerr &lt;&lt; x.Zeil;
  s &gt;&gt; x.farbtiefe; 
  cerr &lt;&lt; x.farbtiefe;
  s &gt;&gt; ws;

  x.Resize(x.Zeil,x.Spalt);   
 // cout &lt;&lt; setiosflags(ios::right);
  for (int i=0; i&lt;x.Zeil; i++)
    for (int j=0; j&lt;x.Spalt; j++)
  {
    s &gt;&gt; ws;
    s &gt;&gt; x.Mat[i][j];
    x.Mat[i][j] = x.Mat[i][j] / x.farbtiefe;
    s &gt;&gt; ws;
    cout &lt;&lt;&quot; (&quot;&lt;&lt;i&lt;&lt;&quot;,&quot;&lt;&lt;j&lt;&lt;&quot;)&quot;&lt;&lt; x.Mat[i][j];   
  }
  return s;
}
</code></pre>
<p>Danke schon mal!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/169104/array-grenzen-werden-grundlos-überschritten</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 16:19:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/169104.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Jan 2007 00:21:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Array-Grenzen werden Grundlos überschritten... on Tue, 02 Jan 2007 00:21:25 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">x.Resize(x.Zeil,x.Spalt);   
 // cout &lt;&lt; setiosflags(ios::right);
  for (int i=0; i&lt;x.Zeil; i++)
    for (int j=0; j&lt;x.Spalt; j++)
  {
    s &gt;&gt; ws;
    s &gt;&gt; x.Mat[i][j];
    x.Mat[i][j] = x.Mat[i][j] / x.farbtiefe;
    s &gt;&gt; ws;
    cout &lt;&lt;&quot; (&quot;&lt;&lt;i&lt;&lt;&quot;,&quot;&lt;&lt;j&lt;&lt;&quot;)&quot;&lt;&lt; x.Mat[i][j];   
  }
  return s;
</code></pre>
<p>Das ist ein Teil aus meiner Einlese - Funktion. Ich lese dabei eine PGM Datei in die Matrix x ein.<br />
Mittels Debug Ausgaben habe ich herausgefunden, dass die Daten x.Zeil und X.Spalt (Dimension der Matrix) sauber übergeben werden. Dennoch ruft mein Programm den Eintrag (0,158) auf, obwohl die Forschleife ja offenbar nur bis x.spalt geht (in diesem Beispiel 157). Ich kann mir diesen Fehler einfach überhaupt gar nicht erklären. Hat hier vielleicht jemand ne Idee, woran es liegen könnte? Oder hatte schon mal jemand ein ähnliches Problem? NAbei der komplette wichtige Quellcode:</p>
<pre><code class="language-cpp">class GreyScale
{
  private:
    float** Mat;                          // Zeiger auf Feld fuer Matrixelemente
    int     Zeil,Spalt,farbtiefe;                        // Matrixlaenge

  public:
    GreyScale  (int m=0,int n=0);                    // Konstruktor mit Laengenangabe
    ~GreyScale () { delete[] Mat; }          // Destruktor
    GreyScale  (const GreyScale&amp;);              // Kopierkonstruktor

    float&amp; operator () (int,int);            // Matrixelement schreiben
    float  operator () (int,int) const;      // Matrixelement lesen

    GreyScale&amp; operator =  (const GreyScale&amp;);  // Zuweisung
    GreyScale&amp; operator += (const GreyScale&amp;);  // Zuweisungen mit arithm. Operation
    GreyScale&amp; operator -= (const GreyScale&amp;);
    GreyScale&amp; operator *= (float);
    GreyScale&amp; operator /= (float);

    GreyScale&amp; Resize   (int,int);                      // neue Laenge festlegen
    int     GetHeight  () const { return Zeil; }    // Zeilenanzahl
    int     GetWidth  () const { return Spalt; }    // Zeilenanzahl
    int     GetDeepth  () const { return farbtiefe; }    // Zeilenanzahl

    static void MatFehler (const char str[]);   // Fehlermeldung ausgeben

    friend GreyScale   operator +  (const GreyScale&amp;, const GreyScale&amp;); // Addition
    friend GreyScale   operator -  (const GreyScale&amp;, const GreyScale&amp;); // Subtraktion
    friend GreyScale   operator -  (const GreyScale&amp;);                // Vorzeichen

    friend GreyScale   operator *  (const GreyScale&amp;, const GreyScale&amp;); // Matrixprodukt
    friend GreyScale   operator *  (double, const GreyScale&amp;);        // Vielfache
    friend GreyScale   operator *  (const GreyScale&amp;, float);
    friend GreyScale   operator /  (const GreyScale&amp;, float);

    friend bool     operator == (const GreyScale&amp;, const GreyScale&amp;); // Vergleich
    friend bool     operator != (const GreyScale&amp;, const GreyScale&amp;);

    friend istream&amp; operator &gt;&gt; (istream&amp;, GreyScale&amp;);            // Eingabe
    friend ostream&amp; operator &lt;&lt; (ostream&amp;, const GreyScale&amp;);      // Ausgabe

};

GreyScale::GreyScale (int m,int n)
{
  if (m&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Zeilenanzahl!&quot;);
  if (n&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Spaltenanzahl!&quot;);    

  Zeil=m;
  Spalt=n;

  Mat=new float*[m];
  for(int i=0; i&lt;m; i++)
    Mat[i]=new float [n];
  if (Mat==NULL)
    MatFehler(&quot;Nicht genuegend Speicher!&quot;);

  for (int i=0; i&lt;m; i++)
    for(int j=0; j&lt;n; j++)
      Mat[i][j]=0;
}

GreyScale&amp; GreyScale::Resize (int m, int n)
{        
  delete[] Mat;      
  if (m&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Zeilenanzahl!&quot;);
  if (n&lt;0)
    MatFehler(&quot;Nur Matrizen mit positiver Spaltenanzahl!&quot;);    

  Zeil=m;
  Spalt=n;

  Mat=new float*[m];
  for(int i=0; i&lt;m; i++)
    Mat[i]=new float [n];
  if (Mat==NULL)
    MatFehler(&quot;Nicht genuegend Speicher!&quot;);

  for (int i=0; i&lt;m; i++)
    for(int j=0; j&lt;n; j++)
      Mat[i][j]=0;
  return *this;    
}

istream&amp; operator &gt;&gt; (istream &amp;s, GreyScale &amp;x)
{
  char b;
  b=s.get();
  cerr &lt;&lt; b; 
  if (b != 'P') GreyScale::MatFehler(&quot;Falsches Dateiformat!&quot;);
  b=s.get();
  cerr &lt;&lt; b; 
  if (b != '2') GreyScale::MatFehler(&quot;Falsches Dateiformat!&quot;); 
  s &gt;&gt; ws;
  while( s.peek() == '#')
  {
    s.ignore( 10000, '\n');  // ignore characters until line end
    s &gt;&gt; std::ws;            // eat whitespaces
  }
  s &gt;&gt; x.Spalt;
  cerr &lt;&lt; x.Spalt;
  s &gt;&gt; x.Zeil; s &gt;&gt; ws;
  cerr &lt;&lt; x.Zeil;
  s &gt;&gt; x.farbtiefe; 
  cerr &lt;&lt; x.farbtiefe;
  s &gt;&gt; ws;

  x.Resize(x.Zeil,x.Spalt);   
 // cout &lt;&lt; setiosflags(ios::right);
  for (int i=0; i&lt;x.Zeil; i++)
    for (int j=0; j&lt;x.Spalt; j++)
  {
    s &gt;&gt; ws;
    s &gt;&gt; x.Mat[i][j];
    x.Mat[i][j] = x.Mat[i][j] / x.farbtiefe;
    s &gt;&gt; ws;
    cout &lt;&lt;&quot; (&quot;&lt;&lt;i&lt;&lt;&quot;,&quot;&lt;&lt;j&lt;&lt;&quot;)&quot;&lt;&lt; x.Mat[i][j];   
  }
  return s;
}
</code></pre>
<p>Danke schon mal!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200888</guid><dc:creator><![CDATA[Seppo]]></dc:creator><pubDate>Tue, 02 Jan 2007 00:21:25 GMT</pubDate></item><item><title><![CDATA[Reply to Array-Grenzen werden Grundlos überschritten... on Tue, 02 Jan 2007 06:35:32 GMT]]></title><description><![CDATA[<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-120832.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-120832.html</a><br />
Auch wenn du nicht VC 6 hast kannst du da was lernen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200912</guid><dc:creator><![CDATA[nkb.]]></dc:creator><pubDate>Tue, 02 Jan 2007 06:35:32 GMT</pubDate></item></channel></rss>