<?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[Nicht verständliche Warnung vom Compiler]]></title><description><![CDATA[<p>Hallo,</p>
<p>bei folgendem Code:</p>
<pre><code>#include &lt;windows.h&gt;
struct _player_ {
	int health = 100;
	int armor = 250;
	int strenght = 5;
};
int main (int argc,char ** argv) {
	_player_ Erwin;
	cout &lt;&lt; Erwin.health;
	cout &lt;&lt; &quot;\n&quot;;
	cout &lt;&lt; (Erwin.armor);
	cout &lt;&lt; (&quot;\n&quot;);
	cout &lt;&lt; (Erwin.strenght);
	system (&quot;pause &gt; NUL&quot;);
	return 0;
};
</code></pre>
<p>bekomme ich folgende Warnungen vom Compiler:</p>
<blockquote>
<p>[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]<br />
[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]<br />
[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]</p>
</blockquote>
<p>Was soll das denn bedeuten? Wenn ich die Member des structs mit static ausstatte, dann bekomme ich folgende Fehler:</p>
<blockquote>
<p>[Error] ISO C++ forbids in-class initialization of non-const static member '_player_::health'<br />
[Error] ISO C++ forbids in-class initialization of non-const static member '_player_::armor'<br />
[Error] ISO C++ forbids in-class initialization of non-const static member '_player_::strenght'</p>
</blockquote>
<p>Aber ich möchte ja keine Konstanten deklarieren bzw. definieren.<br />
Kann ich die Warnung (s. o.) einfach ignorieren?</p>
<p>Danke im Voraus!</p>
<p>MfG</p>
<p>Seikuassi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/318061/nicht-verständliche-warnung-vom-compiler</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 19:48:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318061.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Jun 2013 12:48:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 12:48:56 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>bei folgendem Code:</p>
<pre><code>#include &lt;windows.h&gt;
struct _player_ {
	int health = 100;
	int armor = 250;
	int strenght = 5;
};
int main (int argc,char ** argv) {
	_player_ Erwin;
	cout &lt;&lt; Erwin.health;
	cout &lt;&lt; &quot;\n&quot;;
	cout &lt;&lt; (Erwin.armor);
	cout &lt;&lt; (&quot;\n&quot;);
	cout &lt;&lt; (Erwin.strenght);
	system (&quot;pause &gt; NUL&quot;);
	return 0;
};
</code></pre>
<p>bekomme ich folgende Warnungen vom Compiler:</p>
<blockquote>
<p>[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]<br />
[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]<br />
[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]</p>
</blockquote>
<p>Was soll das denn bedeuten? Wenn ich die Member des structs mit static ausstatte, dann bekomme ich folgende Fehler:</p>
<blockquote>
<p>[Error] ISO C++ forbids in-class initialization of non-const static member '_player_::health'<br />
[Error] ISO C++ forbids in-class initialization of non-const static member '_player_::armor'<br />
[Error] ISO C++ forbids in-class initialization of non-const static member '_player_::strenght'</p>
</blockquote>
<p>Aber ich möchte ja keine Konstanten deklarieren bzw. definieren.<br />
Kann ich die Warnung (s. o.) einfach ignorieren?</p>
<p>Danke im Voraus!</p>
<p>MfG</p>
<p>Seikuassi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335233</guid><dc:creator><![CDATA[PHBU]]></dc:creator><pubDate>Sat, 29 Jun 2013 12:48:56 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 12:52:00 GMT]]></title><description><![CDATA[<p>Du kannst so ohne weiteres in C++ nicht deinen Membervariablen einen Startwert mitgeben(wie z.B. in Java). Das ist erst im neuen Standard möglich, und genau das rät dir der Compiler auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335235</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 29 Jun 2013 12:52:00 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 12:59:01 GMT]]></title><description><![CDATA[<p>Hallo Skym0sh0,</p>
<blockquote>
<p>Du kannst so ohne weiteres in C++ nicht deinen Membervariablen einen Startwert mitgeben [...]</p>
</blockquote>
<p>Aber warum denn nicht? Denn jede Variable, die vom Datentyp _player_ kommt, besitzt doch diesen Startwert. Es gibt ja so eine (oder vllt. mehrere) Möglichkeit mit Vererbungen oder ähnlich, mit dem ich einen Startwert ohne Warnung initialisieren kann, oder?<br />
Was wäre denn jetzt die kürzeste Initialisierungsmöglichkeit, die man anwenden könnte?</p>
<p>Oder anders gefragt: Was für Gefahren bergen sich hinter meiner Initialisierung?</p>
<p>Danke im Voraus!</p>
<p>MfG</p>
<p>Seikuassi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335240</guid><dc:creator><![CDATA[PHBU]]></dc:creator><pubDate>Sat, 29 Jun 2013 12:59:01 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 13:04:38 GMT]]></title><description><![CDATA[<p>Es gibt keine Gefahren. Benutze es einfach, soweit du mit dem Feature vertraut bist. Du musst nur deinem GCC das entsprechende Flag mitgeben, damit er standardkonform arbeitet: -std=c++11 oder -std=gnu++11 (für Erweiterungen).</p>
<blockquote>
<p>Denn jede Variable, die vom Datentyp _player_ kommt, besitzt doch diesen Startwert.</p>
</blockquote>
<p>Ja, das ist richtig. __player__ ist kein Aggregat und hat auch keine entsprechenden Konstruktoren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335242</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 29 Jun 2013 13:04:38 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 13:11:05 GMT]]></title><description><![CDATA[<p>Hallo nochmal,</p>
<blockquote>
<p>Es gibt keine Gefahren. Benutze es einfach, soweit du mit dem Feature vertraut bist.</p>
</blockquote>
<p>Okay, danke! Sollte es Probleme geben, werde ich erst nach den structs gucken, wobei ich denke, dass das unnötig sein wird. Denn auch wenn es vllt. jemand stört oder als &quot;Misshandlung&quot; versteht, ich benutze structs meistens nur als Variablencontainer bzw. Datencontainer. Für Funktionen benutze ich namespaces und Klassen (die ja eigentlich structs entsprechen (außer mit der public-private-Geschichte)) eher selten.</p>
<p>Also danke nochmal!</p>
<p>MfG</p>
<p>Seikuassi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335247</guid><dc:creator><![CDATA[PHBU]]></dc:creator><pubDate>Sat, 29 Jun 2013 13:11:05 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 13:18:43 GMT]]></title><description><![CDATA[<p>Obligatorischer Hinweis: _player_ ist im globalen Namensraum ein reservierter Bezeichner, den du nicht verwenden darfst (sondern nur der Compiler/die Standardbibliothek).</p>
<p>Allgemeine Regeln: Für die Implementation (Compiler/Standardbibliothek) reserviert sind</p>
<p>1. Bezeichner, die mit einem Unterstrich gefolgt von einem Großbuchstaben beginnen (etwa <em>Foo)<br />
2. Bezeichner, die zwei Unterstriche in Folge enthalten (etwa __foo, foo__bar)<br />
3. im globalen Namensraum alle Bezeichner, die mit einem Unterstrich beginnen (etwa _foo, _player</em>).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335248</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sat, 29 Jun 2013 13:18:43 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 13:21:39 GMT]]></title><description><![CDATA[<p>Seikuassi schrieb:</p>
<blockquote>
<blockquote>
<p>Du kannst so ohne weiteres in C++ nicht deinen Membervariablen einen Startwert mitgeben [...]</p>
</blockquote>
<p>Aber warum denn nicht?</p>
</blockquote>
<p>Warum das nicht geht leigt daran, dass es früher nicht möglich war.<br />
Und warum es früher nicht ging, weiss ich nicht (ich tippe auf die Verletzung der ODR, aber kA, das liegt vor meiner Zeit).</p>
<p>Ich finde es auf die Art, wie du es machst, auch viel besser und einfacher. Aber es ist halt noch sehr neu und wird nicht überall unterstützt.</p>
<p>Der &quot;alte&quot; Weg ist der hier:</p>
<pre><code>struct _player_ {
    int health = 100;
    int armor = 250;
    int strenght = 5;

	_player_()
	 : health(100), armor(250), strenght(5)
	{ }
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2335249</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335249</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 29 Jun 2013 13:21:39 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 17:15:43 GMT]]></title><description><![CDATA[<p>Es ging früher nicht, weil der alte Standard es nicht vorsieht.<br />
Nicht alles was der alte Standard nicht vorsieht hat technische Gründe.<br />
Und auch nicht alles was der neue Standard nicht vorsieht hat technische Gründe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335308</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 29 Jun 2013 17:15:43 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 17:17:30 GMT]]></title><description><![CDATA[<p>Ok, dann anders gefragt. Wieso war das nichtso? Wurde da keine Gründe genannt?</p>
<p>Oder umgekehrt: Was sind die Vor- und Nachteile?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335309</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sat, 29 Jun 2013 17:17:30 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sat, 29 Jun 2013 18:36:40 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Ok, dann anders gefragt.</p>
</blockquote>
<p>Vermutlich weil niemand daran gedacht hat...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335329</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335329</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Sat, 29 Jun 2013 18:36:40 GMT</pubDate></item><item><title><![CDATA[Reply to Nicht verständliche Warnung vom Compiler on Sun, 30 Jun 2013 09:12:02 GMT]]></title><description><![CDATA[<p>Compiler Options -&gt; Other Options und einfach<br />
-std=gnu++11<br />
reinsetzten. (Code::Blocks + GCC)</p>
<p>mfg<br />
HarteWare<br />
Edit: lol... ich werds ab jetzt wohl entgültig lassen.. P.S. ist keine Absicht! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2335394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2335394</guid><dc:creator><![CDATA[HarteWare]]></dc:creator><pubDate>Sun, 30 Jun 2013 09:12:02 GMT</pubDate></item></channel></rss>