<?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[&amp;quot;new&amp;quot; manipulation]]></title><description><![CDATA[<p>Hallo an alle,</p>
<p>ist es möglich, den Operator &quot;new&quot; auf eine class &quot;xy&quot; so aus dem ctor der class &quot;xy&quot; heraus zu füttern, dass &quot;new&quot; aus dem ctor von xy heraus 0 zurück liefert? Das würde mir eine Abfrage wie if ( xy::valid() == 0 ) { delete xy } ersparen.</p>
<p>Danke vorab,</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/295896/quot-new-quot-manipulation</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 05:15:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/295896.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Nov 2011 22:24:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Sun, 27 Nov 2011 13:37:46 GMT]]></title><description><![CDATA[<p>Hallo an alle,</p>
<p>ist es möglich, den Operator &quot;new&quot; auf eine class &quot;xy&quot; so aus dem ctor der class &quot;xy&quot; heraus zu füttern, dass &quot;new&quot; aus dem ctor von xy heraus 0 zurück liefert? Das würde mir eine Abfrage wie if ( xy::valid() == 0 ) { delete xy } ersparen.</p>
<p>Danke vorab,</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2148015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148015</guid><dc:creator><![CDATA[chezz]]></dc:creator><pubDate>Sun, 27 Nov 2011 13:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Wed, 23 Nov 2011 22:32:39 GMT]]></title><description><![CDATA[<p>Nachdem ich nach dem 2. mal Lesen jetzt fast sicher bin deinen etwas krumm formulierten Satz verstanden zu haben...</p>
<p>Nein, das ist nicht möglich. Im Konstruktor hast du keine Möglichkeit mehr die Adresse des Objekts, die dann ja von &quot;new&quot; zurückgegeben wird, zu ändern.</p>
<p>Mit bekannte Optionen, von &quot;mag ich&quot; nach &quot;mag ich nicht&quot; sortiert:</p>
<ol>
<li>Im Ctor eine Exception werfen</li>
<li>Named-Ctor aka. Factory-Funktion (&quot;xy::create()&quot;)</li>
<li>In der Klasse xy einen eigenen &quot;operator new&quot; definieren, der dann erst checkt ob das Objekt erzeugt werden kann, und falls nicht einfach NULL zurückgibt</li>
<li>Two-Phase Construction (&quot;if (!xy.initialize()) ...&quot;)</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/2148018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148018</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 23 Nov 2011 22:32:39 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Wed, 23 Nov 2011 22:42:47 GMT]]></title><description><![CDATA[<p>Gottseidank gibt es Profis wie euch.</p>
<p>Deine Variante liefe also so?</p>
<p>try<br />
{<br />
XY xy = new XY();<br />
}<br />
catch ( xy.exception )<br />
{<br />
xy = 0;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2148022</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148022</guid><dc:creator><![CDATA[chezz]]></dc:creator><pubDate>Wed, 23 Nov 2011 22:42:47 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Wed, 23 Nov 2011 22:56:22 GMT]]></title><description><![CDATA[<p>Optimalerweise kann man mehrere Klassen und Funktionen zu einer gedachten Gruppe zusammenfassen, die alle die gleiche Exception werfen. Oder man baut sich Exceptions für das aktuelle Projekt. Jedenfalls würde ich nicht für jedes Objekt eine eigene Exceptionklasse anlegen, das wird doch ein heilloses gefange. Der Sinn sollte doch eigentlich sein, relativ weit &quot;oben&quot; zu fangen, und sich dann in den niedrigeren Funktionen gar nicht mehr um die Fehlerbehandlung kümmern zu müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2148025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148025</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 23 Nov 2011 22:56:22 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Wed, 23 Nov 2011 22:59:49 GMT]]></title><description><![CDATA[<p>chezz schrieb:</p>
<blockquote>
<p>Deine Variante liefe also so? [...]</p>
</blockquote>
<p>Wohl eher so:</p>
<pre><code class="language-cpp">std::unique_ptr&lt;XY&gt; xy(new XY());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2148026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148026</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Wed, 23 Nov 2011 22:59:49 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Thu, 24 Nov 2011 08:31:52 GMT]]></title><description><![CDATA[<p>chezz schrieb:</p>
<blockquote>
<p>Deine Variante liefe also so?</p>
<p>try<br />
{<br />
XY xy = new XY();<br />
}</p>
</blockquote>
<p>Ganz sicher nicht, das wäre nichtmal gültiges C++. Gib uns mal bitte dein konkretes Beispiel, was du hast und was du erreichen willst. Das klingt mir irgendwie nach &quot;von hinten durch die Brust ins Auge&quot;, was du da anstellst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2148071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148071</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 24 Nov 2011 08:31:52 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Fri, 25 Nov 2011 09:01:22 GMT]]></title><description><![CDATA[<p>bottom up...</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9960">@pumuckl</a>: das sollte nur pseudocode sein.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6496">@dot</a>: völlig neu für mich. Werde ich mir morgen mal ansehen.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/25760">@cooky451</a>: hab mir erstmalnur eine exception-class gemacht, die ints wirft.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/13960">@hustbaer</a>: ich komme zwar sauber raus aus dem ctor, aber im catch knallts bei &quot;delete xy&quot;. Morgen mehr, muss ins bett.</p>
<pre><code class="language-cpp">XY::XY( char* arg )
{
    ...

    if ( arg == 0 )
    {
         throw myException( 1 );
         // return;
    }

    ...
}

//-----------------------------------

#include &quot;myException.h&quot;

class myException;

XY* xy = 0;
try
{
xy = new XY( 0 );
}
catch ( myException &amp; e )
{
delete xy; // &lt;- xy != 0 aber trotzdem crash
xy = 0;
}
</code></pre>
<p>Danke an euch!</p>
<p>/edit pumuckl: cpp-Tags spendiert. Bitte künftig selber machen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2148567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148567</guid><dc:creator><![CDATA[chezz]]></dc:creator><pubDate>Fri, 25 Nov 2011 09:01:22 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Fri, 25 Nov 2011 07:14:11 GMT]]></title><description><![CDATA[<p>wenn du im catch landest, wurde kein Objekt erzeugt, also kannst du auch nichts zerstören... xy sollte außerdem weiterhin 0 sein.</p>
<p>greetz KN4CK3R</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2148594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2148594</guid><dc:creator><![CDATA[KN4CK3R]]></dc:creator><pubDate>Fri, 25 Nov 2011 07:14:11 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;new&amp;quot; manipulation on Sun, 27 Nov 2011 13:22:17 GMT]]></title><description><![CDATA[<p>Die letzten Tage hab' ich viel geproggt.</p>
<p>Man lernt ja nie aus ...</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9960">@pumuckl</a>: Danke für's Editieren.<br />
@knacker: Wer Zeile 21 vergisst, ist selber Schuld!<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6496">@dot</a>: Da könnten noch Frage meinerseits kommen...<br />
@cookie451:</p>
<pre><code class="language-cpp">static_cast&lt;OffTopic*&gt;( OtherThread )
</code></pre>
<p>Menschen mit zwei Augen sind nach reichlicher Reisetätigkeit in alle Kontinente definitiv &quot;normal&quot;.</p>
<p>Nochmals ein herzliches &quot;Danke&quot; an euch und eure Denkanstösse.</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2149486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2149486</guid><dc:creator><![CDATA[chezz]]></dc:creator><pubDate>Sun, 27 Nov 2011 13:22:17 GMT</pubDate></item></channel></rss>