<?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[Stringarray einer klasse initialisieren??]]></title><description><![CDATA[<p>Hallo</p>
<pre><code class="language-cpp">class MyEx
{
  public:
   MyEx(int errornumber)
   {
    m_errnr = errornumber;
   }
  private:
   int m_errnr;
   const string failuretext[3];
};

string MyEx::failuretext={&quot;Test&quot;,&quot;Hallo&quot;,&quot;Sie&quot;};
</code></pre>
<p>er sagt mir, das Bezeichner MyEx failuretext mehrfach deklariert ist!<br />
stimmt ja, aber wie kann ich den string initialisieren??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/140379/stringarray-einer-klasse-initialisieren</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 03:32:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/140379.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Mar 2006 14:35:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stringarray einer klasse initialisieren?? on Tue, 14 Mar 2006 14:35:42 GMT]]></title><description><![CDATA[<p>Hallo</p>
<pre><code class="language-cpp">class MyEx
{
  public:
   MyEx(int errornumber)
   {
    m_errnr = errornumber;
   }
  private:
   int m_errnr;
   const string failuretext[3];
};

string MyEx::failuretext={&quot;Test&quot;,&quot;Hallo&quot;,&quot;Sie&quot;};
</code></pre>
<p>er sagt mir, das Bezeichner MyEx failuretext mehrfach deklariert ist!<br />
stimmt ja, aber wie kann ich den string initialisieren??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1016081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1016081</guid><dc:creator><![CDATA[sadasdsa]]></dc:creator><pubDate>Tue, 14 Mar 2006 14:35:42 GMT</pubDate></item><item><title><![CDATA[Reply to Stringarray einer klasse initialisieren?? on Tue, 14 Mar 2006 14:44:52 GMT]]></title><description><![CDATA[<p>Entweder im Konstruktor, wie bei nonstatischen Membern eigentlich üblich, oder Du machst die Konstante static.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1016089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1016089</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 14 Mar 2006 14:44:52 GMT</pubDate></item><item><title><![CDATA[Reply to Stringarray einer klasse initialisieren?? on Tue, 14 Mar 2006 14:46:33 GMT]]></title><description><![CDATA[<p>hab mir erstmal über ein dynamisches array geholfen....aber</p>
<pre><code class="language-cpp">class MyEx
{
  public:
   MyEx(int errornumber)
   {
    failuretext = new string[3];
    failuretext[0] = &quot;Division durch Null&quot;;
    failuretext[1] = &quot;Integerüberlauf&quot;;
    failuretext[2] = &quot;Integerunterlauf&quot;;
    m_errnr = errornumber;
   }
   ~MyEx(){delete[] failuretext;}
   const string What()
   {
    return failuretext[m_errnr];
   }
  private:
   int m_errnr;
   string *failuretext;
};

int test(int a)
{
 if(a == 0)
  throw MyEx(0);
 else if(a == 1)
  throw MyEx(1);
  else if (a == 2)
  throw MyEx(2);
 else
  throw MyEx(10);

}

int main(int argc, char* argv[])
{
  try
  {
   test(3);
  }
  catch(MyEx&amp; exc)
  {
   cout&lt;&lt;exc.What();
  }
  getch();
  return 0;
}
//---------------------------------------------------------------------------
</code></pre>
<p>jetzt zeigt er mir nix an, aber das fenster schließt sofort!<br />
wieso?</p>
<p>getch() am ende steht</p>
<p>wenn ich test mit 0 aufrufe, kommen viele lustige zeichen auf dem bildschirm!</p>
<p>wo liegt also der fehler??</p>
<p>btw, die frage mit dem &quot;konstanten&quot; initialisieren des stringarrys steht noch!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1016090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1016090</guid><dc:creator><![CDATA[sadasdsa]]></dc:creator><pubDate>Tue, 14 Mar 2006 14:46:33 GMT</pubDate></item><item><title><![CDATA[Reply to Stringarray einer klasse initialisieren?? on Tue, 14 Mar 2006 15:16:06 GMT]]></title><description><![CDATA[<p>Und ich antworte Dir gerne nochmal:</p>
<p>Du musst die Konstante static machen, dann geht es wie von Dir oben gedacht.<br />
Non-static musst Du die Konstante wie jedes andere Member initialisieren, im Konstruktor der Klasse.</p>
<p>EDIT:</p>
<p>Falsch</p>
<pre><code class="language-cpp">class MyEx {
private:
  int m_errnr;
  const string failuretext[3];
};
string MyEx::failuretext={&quot;Test&quot;,&quot;Hallo&quot;,&quot;Sie&quot;};
</code></pre>
<p>Richtig</p>
<pre><code class="language-cpp">class MyEx {
private:
  int m_errnr;
  static const string failuretext[3];
};
string MyEx::failuretext={&quot;Test&quot;,&quot;Hallo&quot;,&quot;Sie&quot;};
</code></pre>
<p>Auch Richtig</p>
<pre><code class="language-cpp">class MyEx {
public:
  MyEx() { failuretext[0]=&quot;Test&quot;; failuretext[1]=&quot;Hallo&quot;; ... }
private:
  int m_errnr;
  const string failuretext[3];
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1016103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1016103</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 14 Mar 2006 15:16:06 GMT</pubDate></item></channel></rss>