<?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[Funktionspointer einer Funktion in einem Objekt]]></title><description><![CDATA[<p>Wie der Titel schon sagt suche ich eine Möglichkeit einen<br />
Funktionspointer einer Funktions zu bekommen die sich in<br />
einem Objekt befindet oder kennt jemand noch ne andere möglichkeit<br />
boost::thread zu befüttern!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/177252/funktionspointer-einer-funktion-in-einem-objekt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 22:19:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/177252.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Mar 2007 14:35:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionspointer einer Funktion in einem Objekt on Thu, 29 Mar 2007 14:35:30 GMT]]></title><description><![CDATA[<p>Wie der Titel schon sagt suche ich eine Möglichkeit einen<br />
Funktionspointer einer Funktions zu bekommen die sich in<br />
einem Objekt befindet oder kennt jemand noch ne andere möglichkeit<br />
boost::thread zu befüttern!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255429</guid><dc:creator><![CDATA[Basingstoke]]></dc:creator><pubDate>Thu, 29 Mar 2007 14:35:30 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer einer Funktion in einem Objekt on Thu, 29 Mar 2007 14:45:12 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>was Du suchst, klingt nach &quot;pointer to member function&quot; ... vielleicht findest Du da etwas Passendes drunter (mit boost kann ich Dir leider auch nicht weiterhelfen - weiß nicht, ob die das überhaupt unterstützen).</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255439</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 29 Mar 2007 14:45:12 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer einer Funktion in einem Objekt on Fri, 30 Mar 2007 00:11:45 GMT]]></title><description><![CDATA[<p>Wenn dann würde ich nach &quot;member function pointer&quot; suchen.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/15357">@Basingstoke</a>: nimm doch einfach boost::bind, nicht?</p>
<p>z.B.:</p>
<pre><code class="language-cpp">class foo
{
public:
    void bar();
};

void baz()
{
    boost::shared_ptr&lt;foo&gt; f(new foo);
    boost::shared_ptr&lt;boost::thread&gt; t(new boost::thread(boost::bind(&amp;foo::bar, f)));
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1255691</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255691</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 30 Mar 2007 00:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer einer Funktion in einem Objekt on Fri, 30 Mar 2007 11:28:01 GMT]]></title><description><![CDATA[<p>ja...ok, aber dann müssen die Funktionen doch static sein nich?<br />
also gibt Standard-mäßig keine möglichkeit einen Funktionspointer<br />
einem Objekt zu entlocken ohne das die Funktion static ist?!Hm, ich<br />
war bis jetzt echt überzeugt von C++ aber so langsam vermisse nen<br />
par Sachen!z.B.:Interfaces wie sie in PHP und C# verfügbar sind bekommt<br />
man ja noch einigermaßen mit abstrakten Klassen hin aber das mit den<br />
Funktionspointern macht mich doch schon etwas stutzig...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255925</guid><dc:creator><![CDATA[Basingstoke]]></dc:creator><pubDate>Fri, 30 Mar 2007 11:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer einer Funktion in einem Objekt on Fri, 30 Mar 2007 12:07:08 GMT]]></title><description><![CDATA[<p>Basingstoke schrieb:</p>
<blockquote>
<p>ja...ok, aber dann müssen die Funktionen doch static sein nich?<br />
also gibt Standard-mäßig keine möglichkeit einen Funktionspointer<br />
einem Objekt zu entlocken ohne das die Funktion static ist?!...</p>
</blockquote>
<p>Doch ... aber für den Aufruf brauchst Du immer das konkrete Objekt und üblicherweise sind die Schnittstellen (z.B. der STL evtl. auch boost - weiß nicht) dafür nicht ausgelegt.</p>
<pre><code class="language-cpp">class A {
   public:
      int f(int i);
      int g(int i);
   };

   typedef int (A::*MemberFunc_A)(int);

   int memfunc_test_main(void) {
      MemberFunc_A pFunc = &amp;A::f;

      A a1(1);
      A a2(2);
      (a1.*pFunc)(3); // a1.f(3);
      (a2.*pFunc)(3); // a2.f(3);

      pFunc = &amp;A::g;
      (a1.*pFunc)(3); // a1.g(3);
      (a2.*pFunc)(3); // a2.g(3);

      return 0;
   }
</code></pre>
<p>Die Variablen (a1, a2, pFunc) kann man natürlich auch wiederum Funktionen übergeben, die dann den Aufruf übernehmen...</p>
<p>Wenn man eher die Objekte als die Funktion wechselt oder es nur um die Übergabe an eine Schnittstelle geht, die keine &quot;nonstatic member function pointers&quot; unterstützt, kann man bisweilen entsprechende Funktoren definieren (etwas übersichtichere Syntax):</p>
<pre><code class="language-cpp">// vorgebene API:
   template &lt;typename FuncT&gt;
   int callMeWithInt(FuncT t, int i) { return t(i); }

// selbstgebastelte Funktoren
   struct A_f_Caller {
      A&amp; a;
      A_f_Caller(A&amp; ref) : a(ref) {}
      int operator()(int i) { return a.f(i); }
   };

   struct A_g_Caller {
      A&amp; a;
      A_g_Caller(A&amp; ref) : a(ref) {}
      int operator()(int i) { return a.g(i); }
   };

// so aufgerufen   
   int main(void) {
      A_f_Caller functor_f(a1);
      callMeWithInt(functor_f, 3);

      A_g_Caller functor_g(a2);
      callMeWithInt(functor_g, 3);

      // oder kürzer:
      callMeWithInt(A_f_Caller(a1), 3);
      callMeWithInt(A_g_Caller(a2), 3);

      return 0;
   }
</code></pre>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1255931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1255931</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Fri, 30 Mar 2007 12:07:08 GMT</pubDate></item></channel></rss>