<?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[Überladenen Konstruktor bei gleichem Typ?]]></title><description><![CDATA[<p>Abend!</p>
<p>Folgende struct:</p>
<pre><code>struct Foo {
    float left, right;
};
</code></pre>
<p>Gibt es in C++ irgendwie eine Möglichkeit, so dass ich ein Foo Objekt auf 3 Arten initialisieren kann:</p>
<pre><code>Foo f1(leftValue);
Foo f2(rightValue);
Foo f2(leftValue, rightValue);
</code></pre>
<p>Das Problem ist natürlich der 1. Ctor, der nur einen float bekommt. Hier kann ich ja nicht wissen, ob der linke oder rechte Wert gemeint ist. Gibts da einen Trick?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328619/überladenen-konstruktor-bei-gleichem-typ</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 13:07:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328619.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Oct 2014 17:11:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überladenen Konstruktor bei gleichem Typ? on Sun, 19 Oct 2014 17:11:44 GMT]]></title><description><![CDATA[<p>Abend!</p>
<p>Folgende struct:</p>
<pre><code>struct Foo {
    float left, right;
};
</code></pre>
<p>Gibt es in C++ irgendwie eine Möglichkeit, so dass ich ein Foo Objekt auf 3 Arten initialisieren kann:</p>
<pre><code>Foo f1(leftValue);
Foo f2(rightValue);
Foo f2(leftValue, rightValue);
</code></pre>
<p>Das Problem ist natürlich der 1. Ctor, der nur einen float bekommt. Hier kann ich ja nicht wissen, ob der linke oder rechte Wert gemeint ist. Gibts da einen Trick?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422886</guid><dc:creator><![CDATA[fraggga]]></dc:creator><pubDate>Sun, 19 Oct 2014 17:11:44 GMT</pubDate></item><item><title><![CDATA[Reply to Überladenen Konstruktor bei gleichem Typ? on Sun, 19 Oct 2014 17:30:20 GMT]]></title><description><![CDATA[<p>Nur, dass du weitere Parameter annimmst. Oder du schreisbt dir eine Factory-Funktion, die entsprechend benannt ist...</p>
<pre><code>struct Foo {
    float left, right;

    Foo(float left, float right);
    Foo(float val, bool isLeftValue);
    static Foo createWithLeftValue(float left);
    static Foo createWithRightValue(float right);
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2422891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422891</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 19 Oct 2014 17:30:20 GMT</pubDate></item><item><title><![CDATA[Reply to Überladenen Konstruktor bei gleichem Typ? on Sun, 19 Oct 2014 17:32:25 GMT]]></title><description><![CDATA[<pre><code>Foo(float left = 0, float right = 0) : left(left), right(right) {}
</code></pre>
<p>Für Fall 2 musst du dann <code>0</code> als erstes und <code>rightValue</code> als zweites Argument übergeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422892</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 19 Oct 2014 17:32:25 GMT</pubDate></item></channel></rss>