<?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[Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur?]]></title><description><![CDATA[<p>Hi.</p>
<p>kann mir jemand bei meinem Problem helfen? ich wäre sehr zu dank verpflichtet!</p>
<p>eins vorne weg, me = c/c++ noob</p>
<p>zweitens, warum kann c/c++ den folgenden code nicht ausführen?:</p>
<pre><code>struct Album
    {
        char name[100];
        char kuenstler[100];
        char songname&lsqb;&lsqb;b][u]k[/u][/b&rsqb;&rsqb;[100];
        int song_no;
        int jahr;
    }tamy&lsqb;&lsqb;b][u]j[/u][/b&rsqb;&rsqb;;
</code></pre>
<p>und drittens, wie kann ich letzteres umgehen?</p>
<p>bin für jegliche hilfe dankbar <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/topic/196591/warum-erwartet-c-einen-konstantenausdruck-in-arrays-definiert-in-einer-struktur</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 18:27:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/196591.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 Oct 2007 14:36:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 14:36:03 GMT]]></title><description><![CDATA[<p>Hi.</p>
<p>kann mir jemand bei meinem Problem helfen? ich wäre sehr zu dank verpflichtet!</p>
<p>eins vorne weg, me = c/c++ noob</p>
<p>zweitens, warum kann c/c++ den folgenden code nicht ausführen?:</p>
<pre><code>struct Album
    {
        char name[100];
        char kuenstler[100];
        char songname&lsqb;&lsqb;b][u]k[/u][/b&rsqb;&rsqb;[100];
        int song_no;
        int jahr;
    }tamy&lsqb;&lsqb;b][u]j[/u][/b&rsqb;&rsqb;;
</code></pre>
<p>und drittens, wie kann ich letzteres umgehen?</p>
<p>bin für jegliche hilfe dankbar <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/1395284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395284</guid><dc:creator><![CDATA[Sl4yer-]]></dc:creator><pubDate>Wed, 31 Oct 2007 14:36:03 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 14:40:36 GMT]]></title><description><![CDATA[<p>In Kurzfassung: Wenn C eine Variable anlegen will, muß es wissen, wie groß diese ist - und das wird etwas schwierig, wenn diese Größe von irgendwelchen Vairablen abhängt, die erst zur Laufzeit einen vernünftigen Wert haben.</p>
<p>Als Lösung: Verwende anstelle der Arrays lieber std::vector&lt;&gt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395292</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 31 Oct 2007 14:40:36 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 14:43:12 GMT]]></title><description><![CDATA[<p>Die Antwort ist einfach: Weil es in deinem Code nichts zum Ausführen gibt <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>
<p>Grüße...</p>
<p>Heiko</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395297</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395297</guid><dc:creator><![CDATA[bwbg]]></dc:creator><pubDate>Wed, 31 Oct 2007 14:43:12 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 14:47:58 GMT]]></title><description><![CDATA[<p>danke, ich werde das gleich mal versuchen^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395305</guid><dc:creator><![CDATA[Sl4yer-]]></dc:creator><pubDate>Wed, 31 Oct 2007 14:47:58 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 14:53:42 GMT]]></title><description><![CDATA[<p>Ehm es wäre jetzt etwas komplizierter das mit chars zu machen ... deswegen einmal vereinfachen:</p>
<pre><code class="language-cpp">struct song
{
	char*			name;
	unsigned short	length;

public:
	song() : name(NULL), length(0) {}
	song(const char* name, unsigned short playtime) : length(playtime) 
	{
		this-&gt;name = new char[std::strlen(name) + 1]; 
		std::strcpy(this-&gt;name, name); 
	}
	~song() { delete [] name; }
}

class album
{
	char* m_name;
	char* m_artist;
	song* m_songs;
	std::size_t m_countSong;

public:
	album(const char* name, const char* artist, std::size_t song_count, char** song_names, unsigned short* song_length) : m_countSong(song_count)
	{
		m_name = new char[std::strlen(name) + 1];
		std::strcpy(m_name, name);
		m_artist = new char[std::strlen(artist) + 1];
		std::strcpy(m_artist, artist);
		m_songs = new song[song_count];
		for (std::size_t i = 0; i &lt; song_count; ++i)
		{
			m_songs[i].length = song_length[i];
			m_songs[i].name = new char[std::strlen(song_names[i]) + 1];
			std::strcpy(m_songs[i].name, song_names[i]);
		}    
    }
	~album()
	{
		delete [] m_name;
		delete [] m_artist;
		delete [] m_songs;
	}
};
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395313</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395313</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 31 Oct 2007 14:53:42 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 16:41:33 GMT]]></title><description><![CDATA[<p>auutsch! das zeigt erst wie primitiv meine lösung ist:<br />
(bin momentan dabei mir c++ selbst beizubringen.. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> )</p>
<pre><code class="language-cpp">//-------------------------------------------------------------
#include&lt;iostream&gt;
#include&lt;conio&gt;
#include&lt;stdio&gt;
#include &lt;vector&gt;
//-------------------------------------------------------------
using namespace std;
//-------------------------------------------------------------                           
int main()
{
    int i=0;
    int const j=10;
    int k=0;
    int l=0;
    char buffer[100];
    string str;

    struct Album
    {
        char name[100];
        char kuenstler[100];
        vector&lt;string&gt; songname;
        int song_no;
        int jahr;
    }tamy[j];

    cout&lt;&lt;&quot;Bitte Name des Albums eingeben: &quot;;
    cin&gt;&gt;buffer;
    strcpy(tamy[i].name, buffer);
    cout&lt;&lt;&quot;Bitte Name des Kuenstlers eingeben: &quot;;
    cin&gt;&gt;buffer;
    strcpy(tamy[i].kuenstler, buffer);

    cout&lt;&lt;&quot;Bitte Anzahl Songs eingeben: &quot;;
    cin&gt;&gt;k;
    while(l&lt;k)
    {
        cout&lt;&lt;&quot;Bitte Songname&quot;&lt;&lt;(l+1)&lt;&lt;&quot; angeben: &quot;;
        cin&gt;&gt;str;
        tamy[i].songname.push_back(str);
        //strcpy(tamy[i].songname[k][100], buffer); 
        l++;           
    }

    tamy[i].song_no=k;
    cout&lt;&lt;&quot;Bitte das Jahr des Albums eingeben&quot;&lt;&lt;endl;
    cin&gt;&gt;tamy[i].jahr;

    clrscr();

    cout&lt;&lt;&quot;Folgende Infos zusammengestellt&quot;&lt;&lt;endl; 
    cout&lt;&lt;&quot;Name des Albums: &quot;&lt;&lt;tamy[i].name&lt;&lt;endl;
    cout&lt;&lt;&quot;Kuenstlername: &quot;&lt;&lt;tamy[i].kuenstler&lt;&lt;endl;
    cout&lt;&lt;&quot;Anzahl Lieder: &quot;&lt;&lt;tamy[i].song_no&lt;&lt;&quot; alle anzeigen? (j/n)&quot;&lt;&lt;endl;
    //getch();
    if(getch()=='j')
    {
        l=0;
        while(l&lt;k)
        {
            cout&lt;&lt;&quot;\tSong&quot;&lt;&lt;(l+1)&lt;&lt;&quot;: &quot;&lt;&lt;tamy[i].songname[l]&lt;&lt;endl; 
            l++;           
        }
     }
     cout&lt;&lt;&quot;Release-Jahr des Albums: &quot;&lt;&lt;tamy[i].jahr&lt;&lt;endl;

    getch();
}
//-------------------------------------------------------------

ausgabe:

Folgende Infos zusammengestellt
Name des Albums: Techno_Club_Vol_23
Kuenstlername: VA
Anzahl Lieder: 2 alle anzeigen? (j/n)
        Song1: techno_club_vol_23_cd1_mixed_by_talla_2xlc
        Song2: techno_club_vol_23_cd2_mixed_by_alex_morph_b2b_woody_van_eyden
Release-Jahr des Albums: 2007
</code></pre>
<p>@ Devil könntest du mir eine Zeile deines codes erklären:</p>
<blockquote>
<p>album(const char* name, const char* artist, std::size_t song_count, char** song_names, unsigned short* song_length) : m_countSong(song_count)</p>
</blockquote>
<p>danke schonmal im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395336</guid><dc:creator><![CDATA[Sl4yer-]]></dc:creator><pubDate>Wed, 31 Oct 2007 16:41:33 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 15:23:38 GMT]]></title><description><![CDATA[<p>Das ist ein Konstruktor samt Initialisierungsliste - und dient dazu, ein neues Objekt kontrolliert anzulegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395343</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395343</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 31 Oct 2007 15:23:38 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 15:37:38 GMT]]></title><description><![CDATA[<p>Jap ... und hab die Member alle private gemacht, damit keiner auf die Idee kommt meimne saubere Initialisierung zu zerstören <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /> Wobei du an song_names einen C-String-Array übergeben sollst (C-String ^= char-Array) und song_length einen unsigned short-Array. Die müssen natürlich jeweils so groß sein, dass sie song_count C-String bzw. unsigned short-Werte aufnehen und enthalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395352</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 31 Oct 2007 15:37:38 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 15:41:00 GMT]]></title><description><![CDATA[<p>danke euch für die ausführliche hilfe soweit <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<blockquote>
<p>Never send a human to do a machines job</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1395357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395357</guid><dc:creator><![CDATA[Sl4yer-]]></dc:creator><pubDate>Wed, 31 Oct 2007 15:41:00 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 16:38:24 GMT]]></title><description><![CDATA[<p>(D)Evil, warum verwendest du bei deinem Beispiel nicht einfach std::string?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1395401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395401</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Wed, 31 Oct 2007 16:38:24 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Wed, 31 Oct 2007 18:40:04 GMT]]></title><description><![CDATA[<p>Hmm weil er was von C in der Überschrift stehen hat ... ok Klassen und Objekte usw. sind eh nicht C aber nuja ^^</p>
<p>Für Th:</p>
<pre><code class="language-cpp">struct song
{
    std::string            name;
    unsigned short    length;

public:
    song(std::string const&amp; str = &quot;&quot;, unsigned short playtime = 0) : length(playtime), name(str)
    {}
}

class album
{
    std::string m_name;
    std::string m_artist;
    std::vector&lt;song&gt; m_songs;

public:
    album(std::string const&amp; name, std::string const&amp; artist, std::vector&lt; std::pair&lt;unsigned short, std::string&gt; &gt; const&amp; songs) : m_name(name), m_artist(artist)
    {
        for (std::size_t i = 0; i &lt; songs.size(); ++i)
            m_songs.push_back(song(songs.second, songs.first));
    }
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1395501</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1395501</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 31 Oct 2007 18:40:04 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Fri, 02 Nov 2007 11:35:55 GMT]]></title><description><![CDATA[<p>Ja, so sieht das doch schon recht sauber aus -)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1396341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1396341</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Fri, 02 Nov 2007 11:35:55 GMT</pubDate></item><item><title><![CDATA[Reply to Warum erwartet C einen Konstantenausdruck in arrays definiert in einer struktur? on Fri, 02 Nov 2007 11:46:55 GMT]]></title><description><![CDATA[<p>ich wuerd noch zwei klitzekleine Aenderungen machen:</p>
<ol>
<li>Semikolon hinter der struct song Definition</li>
<li>Das pair im vector im album-Ctor umdrehen:<br />
std::vector &lt;std::pair&lt;std::string, unsigned short&gt; &gt;</li>
</ol>
<p>Ist einfach &quot;natuerlicher&quot;, wenn die Kombi &quot;Songname, Laenge&quot; immer in der gleichen Reihenfolge auftaucht ud nicht mal so, mal so <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/1396350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1396350</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Fri, 02 Nov 2007 11:46:55 GMT</pubDate></item></channel></rss>