<?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[überladung]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
struct foo
{
	template&lt;typename T&gt;
	void x(const T &amp;, bool = true)
	{}

	template&lt;typename T&gt;
	void x(const std::string &amp;, const T &amp;, bool = false)
	{}
};

const char* bar = &quot;X&quot;;

int main()
{
	foo f;
	f.x&lt;std::string&gt;(&quot;asd&quot;, bar);
}
</code></pre>
<p>MSVC schrieb:</p>
<blockquote>
<p><code>test\main.cpp(19) : warning C4800: 'const char *' : forcing value to bool 'true' or 'false' (performance warning)</code></p>
</blockquote>
<p>wieso wird hier nicht der (non-explicit) CTor von <code>std::string</code> aufgerufen sondern die adresse lieber in nen <code>bool</code> umgewandelt? kann man das iwie elegant verhindern?<br />
die default-parameter anzugeben ist unmöglich...<br />
das die überladungen so doof gewählt sind, kann ich leider auch nicht wirklich ändern -.- falls es aber keine andere möglichkeit gibt, muss ich das wohl...</p>
<p>danke schon mal,<br />
bb</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252185/überladung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 18:31:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252185.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Oct 2009 00:25:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to überladung on Fri, 16 Oct 2009 00:25:53 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
struct foo
{
	template&lt;typename T&gt;
	void x(const T &amp;, bool = true)
	{}

	template&lt;typename T&gt;
	void x(const std::string &amp;, const T &amp;, bool = false)
	{}
};

const char* bar = &quot;X&quot;;

int main()
{
	foo f;
	f.x&lt;std::string&gt;(&quot;asd&quot;, bar);
}
</code></pre>
<p>MSVC schrieb:</p>
<blockquote>
<p><code>test\main.cpp(19) : warning C4800: 'const char *' : forcing value to bool 'true' or 'false' (performance warning)</code></p>
</blockquote>
<p>wieso wird hier nicht der (non-explicit) CTor von <code>std::string</code> aufgerufen sondern die adresse lieber in nen <code>bool</code> umgewandelt? kann man das iwie elegant verhindern?<br />
die default-parameter anzugeben ist unmöglich...<br />
das die überladungen so doof gewählt sind, kann ich leider auch nicht wirklich ändern -.- falls es aber keine andere möglichkeit gibt, muss ich das wohl...</p>
<p>danke schon mal,<br />
bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793174</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793174</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 16 Oct 2009 00:25:53 GMT</pubDate></item><item><title><![CDATA[Reply to überladung on Fri, 16 Oct 2009 06:07:47 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>wieso wird hier nicht der (non-explicit) CTor von <code>std::string</code> aufgerufen sondern die adresse lieber in nen <code>bool</code> umgewandelt?</p>
</blockquote>
<p>Weil die Umwandlung mittels ctor einen höheren Rang hat als Standardumwandlung in ein bool. Es gibt verschiedene Möglichkeiten, sofern du die Signaturen ändern kannst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793197</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 16 Oct 2009 06:07:47 GMT</pubDate></item><item><title><![CDATA[Reply to überladung on Fri, 16 Oct 2009 09:01:38 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>wieso wird hier nicht der (non-explicit) CTor von <code>std::string</code> aufgerufen sondern die adresse lieber in nen <code>bool</code> umgewandelt?</p>
</blockquote>
<p>Weil die Umwandlung mittels ctor einen höheren Rang hat als Standardumwandlung in ein bool. Es gibt verschiedene Möglichkeiten, sofern du die Signaturen ändern kannst.</p>
</blockquote>
<p>hmm.. naja - wenns sonst nicht geht, werd ichs wo ändern müssen^^<br />
was wären denn deine vorschläge?</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793243</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793243</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 16 Oct 2009 09:01:38 GMT</pubDate></item><item><title><![CDATA[Reply to überladung on Fri, 16 Oct 2009 09:51:46 GMT]]></title><description><![CDATA[<p>mach aus bar explizit einen temporären std::string:</p>
<pre><code class="language-cpp">f.x(&quot;asd&quot;, std::string(bar));
</code></pre>
<p>Sollte dann klappen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793271</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Fri, 16 Oct 2009 09:51:46 GMT</pubDate></item><item><title><![CDATA[Reply to überladung on Fri, 16 Oct 2009 09:54:24 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>mach aus bar explizit einen temporären std::string:</p>
<pre><code class="language-cpp">f.x(&quot;asd&quot;, std::string(bar));
</code></pre>
<p>Sollte dann klappen.</p>
</blockquote>
<p>ja - so hab ichs zwar momentan im quellcode, aber ich finds iwie hässlich... &gt;&lt;<br />
aber wenn du keinen anderen vorschlag hast, werd ichs wo so lassen müssen!?</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793275</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 16 Oct 2009 09:54:24 GMT</pubDate></item><item><title><![CDATA[Reply to überladung on Fri, 16 Oct 2009 14:51:12 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>was wären denn deine vorschläge?</p>
</blockquote>
<p>Füge weitere Überladungen hinzu, die spezieller sind und die kritischen Fälle abdecken, oder eliminiere die Überladung für bestimmte Argumente (enable_if). Schließlich könnte man den Funktionsaufruf an einen Funktor weiterleiten und mit partieller Spezialiserung statt Überladung arbeiten (etwas mehr Schreibaufwand, dafür leichter richtig hinzubekommen). Was vorzuziehen ist, hängt vom konkreten Einsatz ab. z.B.</p>
<pre><code class="language-cpp">struct foo
{
    template&lt;typename T&gt;
    void x(const T &amp;);

    template&lt;typename T, typename U&gt;
    enable_if&lt;is_same&lt;U,bool&gt; &gt; x(const T &amp;, const U&amp;);

    template&lt;typename T&gt;
    disable_if&lt;is_same&lt;T,bool&gt; &gt; x(const std::string &amp;, const T &amp;, bool = false);
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1793461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793461</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 16 Oct 2009 14:51:12 GMT</pubDate></item></channel></rss>