<?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[Bug (?): Property als Referenz]]></title><description><![CDATA[<p>Hallo,</p>
<p>der C++ Compiler im Borland Developer Studio hat anscheinend ein Problem mit Properties, die eine Referenz zurückgeben. Allerdings nicht immer. Beispielprogramm:</p>
<pre><code class="language-cpp">// Version information:
// Borland® Developer Studio für Microsoft® Windows™ Version 10.0.2166.28377 Update 1  

#include &lt;iostream.h&gt;
#pragma hdrstop

class InnerClass
{
  public:
    void AFunction(int Parameter) { cout &lt;&lt; Parameter &lt;&lt; endl; }
};

class OuterClass
{
  public:
    OuterClass(){}   // compiler wants to have a user-defined constructor
    InnerClass InnerObject;
    InnerClass&amp; ReadInnerObject() { return InnerObject; }
    __property InnerClass&amp; AProperty = { read = ReadInnerObject };
};

#pragma argsused
int main(int argc, char* argv[])
{
  OuterClass OuterObject;

  OuterObject.ReadInnerObject().AFunction(42);    // prints 42
  OuterObject.AProperty.AFunction(43);            // prints 1
  OuterObject.ReadInnerObject().AFunction(44);    // prints 44
  InnerClass&amp; ref = OuterObject.InnerObject;
  ref.AFunction(45);                              // prints 45

  char c;       // wait
  cin &gt;&gt; c;
}
</code></pre>
<p>Weiß jemand etwas näheres darüber, wie sich dieser Bug (sofern es einer ist) beseitigen läßt? (Daß es Workarounds gibt, ist mir klar, siehe den Code.)</p>
<p>Danke,<br />
Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148203/bug-property-als-referenz</link><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Aug 2026 15:57:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148203.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 May 2006 10:28:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Wed, 24 May 2006 10:28:26 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>der C++ Compiler im Borland Developer Studio hat anscheinend ein Problem mit Properties, die eine Referenz zurückgeben. Allerdings nicht immer. Beispielprogramm:</p>
<pre><code class="language-cpp">// Version information:
// Borland® Developer Studio für Microsoft® Windows™ Version 10.0.2166.28377 Update 1  

#include &lt;iostream.h&gt;
#pragma hdrstop

class InnerClass
{
  public:
    void AFunction(int Parameter) { cout &lt;&lt; Parameter &lt;&lt; endl; }
};

class OuterClass
{
  public:
    OuterClass(){}   // compiler wants to have a user-defined constructor
    InnerClass InnerObject;
    InnerClass&amp; ReadInnerObject() { return InnerObject; }
    __property InnerClass&amp; AProperty = { read = ReadInnerObject };
};

#pragma argsused
int main(int argc, char* argv[])
{
  OuterClass OuterObject;

  OuterObject.ReadInnerObject().AFunction(42);    // prints 42
  OuterObject.AProperty.AFunction(43);            // prints 1
  OuterObject.ReadInnerObject().AFunction(44);    // prints 44
  InnerClass&amp; ref = OuterObject.InnerObject;
  ref.AFunction(45);                              // prints 45

  char c;       // wait
  cin &gt;&gt; c;
}
</code></pre>
<p>Weiß jemand etwas näheres darüber, wie sich dieser Bug (sofern es einer ist) beseitigen läßt? (Daß es Workarounds gibt, ist mir klar, siehe den Code.)</p>
<p>Danke,<br />
Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064105</guid><dc:creator><![CDATA[Martin9]]></dc:creator><pubDate>Wed, 24 May 2006 10:28:26 GMT</pubDate></item><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Wed, 24 May 2006 10:39:11 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>das ist kein Fehler vom Builder. Der eintige Fehler ist, das es keine Warnung ausspuckt, weil du eine Referenz auf eine lokale Variable zurückgibst. Deshalb kommt es zu undefiniertem Verhalten und du kannst froh sein, das du überhaupt eine Ausgabe bekommst und keine Zugriffsverletzung.</p>
<p>Um dein Programm korrekt auszuführen, must du das mit Pointern machen</p>
<pre><code class="language-cpp">// Version information:
// Borland® Developer Studio für Microsoft® Windows™ Version 10.0.2166.28377 Update 1  

#include &lt;iostream.h&gt;
#pragma hdrstop

class InnerClass
{
  public:
    void AFunction(int Parameter) { cout &lt;&lt; Parameter &lt;&lt; endl; }
};

class OuterClass
{
  public:
    OuterClass(){}   // compiler wants to have a user-defined constructor
    InnerClass InnerObject;
    InnerClass* ReadInnerObject() { return &amp;InnerObject; }
    __property InnerClass* AProperty = { read = ReadInnerObject };
};

#pragma argsused
int main(int argc, char* argv[])
{
  OuterClass OuterObject;

  OuterObject.ReadInnerObject()-&gt;AFunction(42);    // prints 42
  OuterObject.AProperty-&gt;AFunction(43);            // prints 1
  OuterObject.ReadInnerObject()-&gt;AFunction(44);    // prints 44
  InnerClass&amp; ref = OuterObject.InnerObject;
  ref.AFunction(45);                              // prints 45

  char c;       // wait
  cin &gt;&gt; c;
}
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064117</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Wed, 24 May 2006 10:39:11 GMT</pubDate></item><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Fri, 26 May 2006 06:13:27 GMT]]></title><description><![CDATA[<p>Hallo akari,</p>
<p>vielen Dank für Deine Antwort. Selbige solltest Du aber besser nochmals gründlich überdenken. Entschuldige bitte.</p>
<p>Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1065222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1065222</guid><dc:creator><![CDATA[Martin9]]></dc:creator><pubDate>Fri, 26 May 2006 06:13:27 GMT</pubDate></item><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Fri, 26 May 2006 07:22:49 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>In welcher Beziehung? Meine Veränderung am Code läßt diesen fehlerfrei ablaufen.</p>
<p>Allerdings ist meine Begründung wohl Unsinn, offenbar kommen die Properties wirklich nicht mit Referenzen zurecht.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1065240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1065240</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 26 May 2006 07:22:49 GMT</pubDate></item><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Mon, 29 May 2006 07:56:32 GMT]]></title><description><![CDATA[<p>akari schrieb:</p>
<blockquote>
<p>In welcher Beziehung? Meine Veränderung am Code läßt diesen fehlerfrei ablaufen.</p>
</blockquote>
<p>Das muß aber nicht so bleiben. Immerhin gibst du hier einen Pointer auf ein lokales Objekt (in diesem Fall Klassenmember) zurück. Falls die Klasseninstanz ungültig wird, wird das dein Pointer auch. Hier ist wohl eher eine Kopie angesagt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1067132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1067132</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 29 May 2006 07:56:32 GMT</pubDate></item><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Wed, 31 May 2006 10:57:08 GMT]]></title><description><![CDATA[<p>vergiss das mit <strong>__property</strong> mal wieder ganz schnell. damit baust du dir nur unportierbaren code und unnötigen overhead zusammen!</p>
<p>schon gar nicht würde ich borland-spezifische sachen mit konsolen-anwendungen vermischen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1068669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1068669</guid><dc:creator><![CDATA[BCBler]]></dc:creator><pubDate>Wed, 31 May 2006 10:57:08 GMT</pubDate></item><item><title><![CDATA[Reply to Bug (?): Property als Referenz on Wed, 31 May 2006 11:07:00 GMT]]></title><description><![CDATA[<p>Sehe ich auch so.<br />
Außerdem sollte man das hier</p>
<pre><code class="language-cpp">#include &lt;iostream.h&gt;
</code></pre>
<p>durch das hier ersetzen</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
</code></pre>
<p>Dann wird es standardkonformer. Evtl. ist dann oben noch ein</p>
<pre><code class="language-cpp">using namespace std;
</code></pre>
<p>angebracht oder ein std:: vor den entsprechenden Bezeichnern (cout, cin, endl).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1068684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1068684</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 31 May 2006 11:07:00 GMT</pubDate></item></channel></rss>