<?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[pointer to member function]]></title><description><![CDATA[<p>Hi:</p>
<pre><code class="language-cpp">class A {
public:
  A (int x) : my_x(x) {}

  float do_something (float f) {
     return my_x + f;
  }

private:
  int my_x;
};

class B {
public:
  typedef float (*pt2Func)(float);

  B(pt2Func f) {my_f=f;}

private:
  pt2Func my_f;
};

A a(7);

// Wie jetzt B mit a.do_something Konstruieren?
</code></pre>
<p>Kann jemand helfen?</p>
<p>Danke im vorraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/240326/pointer-to-member-function</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 00:30:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240326.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 May 2009 12:16:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to pointer to member function on Tue, 05 May 2009 12:16:56 GMT]]></title><description><![CDATA[<p>Hi:</p>
<pre><code class="language-cpp">class A {
public:
  A (int x) : my_x(x) {}

  float do_something (float f) {
     return my_x + f;
  }

private:
  int my_x;
};

class B {
public:
  typedef float (*pt2Func)(float);

  B(pt2Func f) {my_f=f;}

private:
  pt2Func my_f;
};

A a(7);

// Wie jetzt B mit a.do_something Konstruieren?
</code></pre>
<p>Kann jemand helfen?</p>
<p>Danke im vorraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705820</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705820</guid><dc:creator><![CDATA[pointerer]]></dc:creator><pubDate>Tue, 05 May 2009 12:16:56 GMT</pubDate></item><item><title><![CDATA[Reply to pointer to member function on Tue, 05 May 2009 12:20:18 GMT]]></title><description><![CDATA[<p>Funktionszeiger funktionieren nur mit statischen member funktionen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705824</guid><dc:creator><![CDATA[derivate]]></dc:creator><pubDate>Tue, 05 May 2009 12:20:18 GMT</pubDate></item><item><title><![CDATA[Reply to pointer to member function on Tue, 05 May 2009 12:24:28 GMT]]></title><description><![CDATA[<p>Hmmm,</p>
<p>aber do_something kann ich nicht statisch machen, da es my_x benutzt ... also unmoeglich ein B mit A.do_something zu konstruieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705830</guid><dc:creator><![CDATA[pointerer]]></dc:creator><pubDate>Tue, 05 May 2009 12:24:28 GMT</pubDate></item><item><title><![CDATA[Reply to pointer to member function on Tue, 05 May 2009 12:27:30 GMT]]></title><description><![CDATA[<p>pointerer schrieb:</p>
<blockquote>
<p>Hmmm,</p>
<p>aber do_something kann ich nicht statisch machen, da es my_x benutzt ... also unmoeglich ein B mit A.do_something zu konstruieren?</p>
</blockquote>
<p>Du kannst es wrappen:</p>
<pre><code class="language-cpp">struct A
{
    //...

    static static_DoSth(A*,f) { A-&gt;do_something(f); }
};

// ...
B( &amp;A::static_DoSth );
</code></pre>
<p>Du musst halt bei jedem Aufruf dein A pointer haben ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705834</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705834</guid><dc:creator><![CDATA[derivate]]></dc:creator><pubDate>Tue, 05 May 2009 12:27:30 GMT</pubDate></item><item><title><![CDATA[Reply to pointer to member function on Tue, 05 May 2009 12:36:05 GMT]]></title><description><![CDATA[<p>pointerer schrieb:</p>
<blockquote>
<p>aber do_something kann ich nicht statisch machen, da es my_x benutzt ... also unmoeglich ein B mit A.do_something zu konstruieren?</p>
</blockquote>
<p>Kurz erklärt:<br />
Eine Funktion &quot;void Foo(int)&quot; und eine statische Methode &quot;void Bar::Foo(int)&quot; können mit einen Zeiger angesprochen werden.</p>
<p>Eine nicht-statische Methode &quot;void Bar::Foo(int)&quot; benötigt aber zudem einen Instanzzeiger (das was du vielleicht als this kennst). Daher reicht ein Zeiger nicht aus.</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705840</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Tue, 05 May 2009 12:36:05 GMT</pubDate></item><item><title><![CDATA[Reply to pointer to member function on Tue, 05 May 2009 21:44:02 GMT]]></title><description><![CDATA[<p>Was Funktionszeiger und Memberfunktionszeiger betrifft: Auf <a href="http://www.newty.de/fpt/index.html" rel="nofollow">http://www.newty.de/fpt/index.html</a> werden diese recht gut erklärt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1706153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1706153</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 05 May 2009 21:44:02 GMT</pubDate></item></channel></rss>