<?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[string- default argument]]></title><description><![CDATA[<p>Warum geht das nicht:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

class game
{
    public:
    inline int get_controller() const {return m_controller;}
    void story_part(string question,
                    string a, string b, string c,
                    string effect1, string effect2=0, string effect3=0);

    private:
    int m_controller;

};

void game::story_part(string question,
                      string a, string b, string c,
                      string effect1, string effect2=0, string effect3=0)
{

}

int main()
{

	return 0;
}
</code></pre>
<p>???</p>
<p>MELDUNG:</p>
<blockquote>
<p>-------------- Build: Debug in GAME ---------------<br />
Compiling: main.cpp<br />
main.cpp:22: error: default argument given for parameter 6 of <code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)' main.cpp:11: error: after previous specification in</code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)'<br />
main.cpp:22: error: default argument given for parameter 7 of <code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)' main.cpp:11: error: after previous specification in</code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)'<br />
Process terminated with status 1 (0 minutes, 0 seconds)<br />
4 errors, 0 warnings</p>
</blockquote>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191410/string-default-argument</link><generator>RSS for Node</generator><lastBuildDate>Sat, 26 Sep 2026 00:03:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191410.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 02 Sep 2007 23:02:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to string- default argument on Sun, 02 Sep 2007 23:02:41 GMT]]></title><description><![CDATA[<p>Warum geht das nicht:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

class game
{
    public:
    inline int get_controller() const {return m_controller;}
    void story_part(string question,
                    string a, string b, string c,
                    string effect1, string effect2=0, string effect3=0);

    private:
    int m_controller;

};

void game::story_part(string question,
                      string a, string b, string c,
                      string effect1, string effect2=0, string effect3=0)
{

}

int main()
{

	return 0;
}
</code></pre>
<p>???</p>
<p>MELDUNG:</p>
<blockquote>
<p>-------------- Build: Debug in GAME ---------------<br />
Compiling: main.cpp<br />
main.cpp:22: error: default argument given for parameter 6 of <code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)' main.cpp:11: error: after previous specification in</code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)'<br />
main.cpp:22: error: default argument given for parameter 7 of <code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)' main.cpp:11: error: after previous specification in</code>void game::story_part(std::string, std::string, std::string, std::string, std::string, std::string, std::string)'<br />
Process terminated with status 1 (0 minutes, 0 seconds)<br />
4 errors, 0 warnings</p>
</blockquote>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357539</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Sun, 02 Sep 2007 23:02:41 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 00:09:18 GMT]]></title><description><![CDATA[<p>Naja, schonmal das versucht:</p>
<p>Stromberg schrieb:</p>
<blockquote>
<pre><code class="language-cpp">...
string effect2=0;
...
</code></pre>
</blockquote>
<p>Klappt auch nicht, oder ?</p>
<p>Anders ausgedrückt: Welche string-Konstruktor soll für effect2 denn aufgerufen werden ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357545</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 03 Sep 2007 00:09:18 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 00:11:40 GMT]]></title><description><![CDATA[<p>Mh, Konstruktor? Ich will des halt so machen, das wenn man für &quot;effect2&quot; und &quot;effect3&quot; nix einträgt, das dann halt in &quot;effet2&quot; und &quot;effect3&quot; 0 drin steht.<br />
Weiß jemand was ich mein?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357546</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357546</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Mon, 03 Sep 2007 00:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 00:14:56 GMT]]></title><description><![CDATA[<p>Stromberg schrieb:</p>
<blockquote>
<p>Mh, Konstruktor? Ich will des halt so machen, das wenn man für &quot;effect2&quot; und &quot;effect3&quot; nix einträgt, das dann halt in &quot;effet2&quot; und &quot;effect3&quot; 0 drin steht.<br />
Weiß jemand was ich mein?</p>
</blockquote>
<p>std::string repräsentiert Zeichenketten, keine Zahlen. 0 ist eine Zahl. Schlussfolgerung: 0 kann nicht in einem std::string drin stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357547</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 03 Sep 2007 00:14:56 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 06:31:07 GMT]]></title><description><![CDATA[<p>versuchs einfach mit effect3 = &quot;0&quot;, dafür sollte es nen konstruktor geben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357584</guid><dc:creator><![CDATA[DrPhil_Guth]]></dc:creator><pubDate>Mon, 03 Sep 2007 06:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 07:46:56 GMT]]></title><description><![CDATA[<p>Stromberg schrieb:</p>
<blockquote>
<p>Mh, Konstruktor? Ich will des halt so machen, das wenn man für &quot;effect2&quot; und &quot;effect3&quot; nix einträgt, das dann halt in &quot;effet2&quot; und &quot;effect3&quot; 0 drin steht....</p>
</blockquote>
<p>Eben: Und wie macht man dass, das in einem Objekt bei der Erzeugung &quot;etwas drinsteht&quot;: Mit dem Konstruktor !<br />
So auch hier.<br />
Übrigens: Soll da wirklich der Buchstabe '0' drinstehen ? Oder möchtest Du nicht viel lieber einen &quot;leeren String&quot; (Also ein &quot;&quot; ) ?</p>
<p>DrPhil_Guth schrieb:</p>
<blockquote>
<p>versuchs einfach mit effect3 = &quot;0&quot;, dafür sollte es nen konstruktor geben.</p>
</blockquote>
<p>Ich vermute halt, dass Du mit</p>
<pre><code class="language-cpp">..., effect3 = &quot;&quot;, ...
</code></pre>
<p>das bekommst, was Du willst.<br />
Es spielt dabei keinen Rolle, ob Du innerhalb einer Parameterliste oder &quot;einfach so&quot; beim Erzeugen eines Objekts einen Initialwert vorgibst: Es muss einen passenden Konstruktor geben.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357612</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 03 Sep 2007 07:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 09:11:24 GMT]]></title><description><![CDATA[<p>Weiterer Fehler:</p>
<p>Bei der Definition der Methode dürfen keine Default-Argument mehr angegeben werden, nur bei der Deklaration!</p>
<p>also:</p>
<pre><code class="language-cpp">class X
{
void y(int x = 0);
};
</code></pre>
<p>und</p>
<pre><code class="language-cpp">void X::y(int x)
{
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1357666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357666</guid><dc:creator><![CDATA[Merker²]]></dc:creator><pubDate>Mon, 03 Sep 2007 09:11:24 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 09:20:08 GMT]]></title><description><![CDATA[<p>Merker² schrieb:</p>
<blockquote>
<p>Bei der Definition der Methode dürfen keine Default-Argument mehr angegeben werden, nur bei der Deklaration!</p>
</blockquote>
<p>Du darfst schon - nur nicht die selben:</p>
<pre><code class="language-cpp">class X
{
  void y(int a,int b=0);
};

void X::y(int a=4711,int b)//übernimmt den Default-Parameter b=0 von der Deklaration
{
  ...
}
</code></pre>
<p>(btw, die Default-Parameter 'string effect3 = 0' sind witzigerweise legal (0 kann in jeden Zeigertyp umgewandelt werden, auch char*), aber wie gut std::string mit einem NULL-Pointer umgehen kann, ist die andere Frage)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357676</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 03 Sep 2007 09:20:08 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 09:35:32 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Du darfst schon - nur nicht die selben:</p>
</blockquote>
<p>Heisst das, die Angabe identischer Defaults an beiden Stellen führt zum Fehler, die Angabe unterschiedlicher Defaults aber nicht?!</p>
<p>Fände ich doch schon suspekt <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>Der GCC meldet übrigens in beiden Fällen einen Fehler.</p>
<p>EDIT:<br />
Falsch verstanden - nicht unterschiedliche Defaults für den selben Parameter, sondern für unterschiedliche Parameter. Finde ich aber trotzdem merkwürdig, heisst das etwa, dass man in der ÜE nach der Definition von X::y diese mit keinem Parameter aufrufen dürfte, in allen anderen ÜE, wo nur die Deklaration vorhanden ist jedoch nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357693</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357693</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 03 Sep 2007 09:35:32 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 09:38:19 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>EDIT:<br />
Falsch verstanden - nicht unterschiedliche Defaults für den selben Parameter, sondern für unterschiedliche Parameter. Finde ich aber trotzdem merkwürdig, heisst das etwa, dass man in der ÜE nach der Definition von X::y diese mit keinem Parameter aufrufen dürfte, in allen anderen ÜE, wo nur die Deklaration vorhanden ist jedoch nicht?</p>
</blockquote>
<p>Ja, das heißt es - praktisch genutzt habe ich das allerdings noch nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357699</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 03 Sep 2007 09:38:19 GMT</pubDate></item><item><title><![CDATA[Reply to string- default argument on Mon, 03 Sep 2007 12:31:00 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>wie gut std::string mit einem NULL-Pointer umgehen kann, ist die andere Frag</p>
</blockquote>
<p>Ausdrücklich undefiniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1357853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1357853</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 03 Sep 2007 12:31:00 GMT</pubDate></item></channel></rss>