<?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[operator smartpoint]]></title><description><![CDATA[<p>Bsp</p>
<pre><code>// class for acquiring and releasing a window handle
class WindowHandle {
public:
   WindowHandle(WINDOW_HANDLE handle): w(handle) {}
  ~WindowHandle() { destroyWindow(w); }

   operator WINDOW_HANDLE() { return w; }        

private:
  WINDOW_HANDLE w;

  // The following functions are declared private to prevent
  // multiple copies of a WINDOW_HANDLE from being created.
  // See Item 28 for a discussion of a more flexible approach.
  WindowHandle(const WindowHandle&amp;);
  WindowHandle&amp; operator=(const WindowHandle&amp;);
};

// this function avoids leaking resources if an
// exception is thrown
void displayInfo(const Information&amp; info)
{
  WindowHandle w(createWindow());

  display info in window corresponding to w;

}
</code></pre>
<p>hier, was ist das? wo ist die Methode aufgerufen?</p>
<pre><code>operator WINDOW_HANDLE() { return w; }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/136964/operator-smartpoint</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 15:54:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/136964.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Feb 2006 14:17:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to operator smartpoint on Tue, 14 Feb 2006 14:17:44 GMT]]></title><description><![CDATA[<p>Bsp</p>
<pre><code>// class for acquiring and releasing a window handle
class WindowHandle {
public:
   WindowHandle(WINDOW_HANDLE handle): w(handle) {}
  ~WindowHandle() { destroyWindow(w); }

   operator WINDOW_HANDLE() { return w; }        

private:
  WINDOW_HANDLE w;

  // The following functions are declared private to prevent
  // multiple copies of a WINDOW_HANDLE from being created.
  // See Item 28 for a discussion of a more flexible approach.
  WindowHandle(const WindowHandle&amp;);
  WindowHandle&amp; operator=(const WindowHandle&amp;);
};

// this function avoids leaking resources if an
// exception is thrown
void displayInfo(const Information&amp; info)
{
  WindowHandle w(createWindow());

  display info in window corresponding to w;

}
</code></pre>
<p>hier, was ist das? wo ist die Methode aufgerufen?</p>
<pre><code>operator WINDOW_HANDLE() { return w; }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/993977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/993977</guid><dc:creator><![CDATA[netrobot]]></dc:creator><pubDate>Tue, 14 Feb 2006 14:17:44 GMT</pubDate></item><item><title><![CDATA[Reply to operator smartpoint on Tue, 14 Feb 2006 14:37:20 GMT]]></title><description><![CDATA[<p>Wenn jemand so etwas tut:</p>
<pre><code class="language-cpp">WindowHandle myHandle;

/* ... */

WINDOW_HANDLE w = myHandle;
</code></pre>
<pre><code class="language-cpp">WindowHandle *myHandle = new WindowHandle();

/* ... */

WINDOW_HANDLE w = *myHandle;
</code></pre>
<p>In beiden Fällen wird der Typ WindowHandle als Typ WINDOW_HANDLE benutzt. Dabei springt der operator WINDOW_HANDLE (sog. Cast-Operator) an und gibt den entsprechenden Wert zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/993999</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/993999</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 14 Feb 2006 14:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to operator smartpoint on Tue, 14 Feb 2006 15:13:34 GMT]]></title><description><![CDATA[<p>damit kann man einen DownCast &quot;vermeiden&quot;? indem man die cast-operation in Base verschiebt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994039</guid><dc:creator><![CDATA[netrobot]]></dc:creator><pubDate>Tue, 14 Feb 2006 15:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to operator smartpoint on Tue, 14 Feb 2006 15:31:07 GMT]]></title><description><![CDATA[<p>Was hat das mit Downcast zu tun?</p>
<p>In dem Beispiel wird eine Klasse (WindowHandle) zu einem Typ (WINDOW_HANDLE, vermutlich ein Typedef für irgendeinen Long-Wert) gecastet. Da der Compiler das ohne operator nicht kann, wird einer definiert.</p>
<p>Das hat also mehr was mit Konvertierungen zu tun. Ich könnte der Klasse std::string z.B. einen &quot;operator const char*&quot; verpassen, dann kann ich das Objekt vom Typ std::string direkt als Dateiname beim ifstream verwenden. Ohne &quot;operator const char*&quot; muss man dort .c_str() benutzen.</p>
<p>EDIT:<br />
Wenn Du Deiner Basisklasse gerne mehrere &quot;operator AbgeleiteteKlasse*&quot; spenden möchtest, klar, damit kann man auch Downcasts verlagern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994056</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 14 Feb 2006 15:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to operator smartpoint on Wed, 15 Feb 2006 09:40:53 GMT]]></title><description><![CDATA[<p>kannst du mir noch ein Beispiel nennen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994570</guid><dc:creator><![CDATA[netrobot]]></dc:creator><pubDate>Wed, 15 Feb 2006 09:40:53 GMT</pubDate></item><item><title><![CDATA[Reply to operator smartpoint on Wed, 15 Feb 2006 09:57:43 GMT]]></title><description><![CDATA[<p>Das beste Beispiel sind wirklich Wrapper-Klassen um irgendwelche C-Datentypen, die möglichst problemlos anstelle des gewrappten Datentyps eingesetzt werden wollen MFC's CString hat einen operator char*()<sup>(1)</sup>, so daß man CString-Objekte an Funktionen weitergeben kann, die mit char-Arrays operieren können (std::string hat aus Design-Gründen keinen), Dialogelement-Klassen können einen operator HANDLE() für den Einsatz mit C WinAPI-Funktionen bereitstellen etc.</p>
<p>(ein Beispiel gibt es auch in der STL - iostreams haben einen operator void*(), damit Konstrukte ala &quot;while(fin&gt;&gt;zahl)...&quot; möglich werden.</p>
<p><sup>(1)</sup> genau genommen hat CString einen operator TCHAR*() - das ist je nach Projekteinstellungen entweder char* oder wchar_t*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/994583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/994583</guid><dc:creator><![CDATA[CStoll (off)]]></dc:creator><pubDate>Wed, 15 Feb 2006 09:57:43 GMT</pubDate></item></channel></rss>