<?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[problem mit statischer callback funktion]]></title><description><![CDATA[<p>hi leute,</p>
<p>ich habe ein problem mit einer callback funktion. Diese muss ja static sein, das problem ist, ich kann dieser kein object der klasse übergeben, weil ich die signatur der funktion nicht aendern darf, die callback function wird bei einer anderen funktion registriert.<br />
nun die frage darf man einen statischen pointer der klasse den this pointer zuweisen (von der klasse foo gibts nur eine instanz!) und dann ueber den statischen pointer auf die elemente der klasse zugreifen, der member i darf auch nicht statisch sein, sonst wärs ja leicht;)</p>
<p>bye</p>
<pre><code class="language-cpp">class foo
{
public:
	foo();
	static foo *ptr_foo;
	static void callback_function();
private:
	int i;
};

foo::foo()
{
	ptr_foo = this;
	i = 10;
}

void foo::callback_function()
{
	ptr_foo-&gt;i = 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/224399/problem-mit-statischer-callback-funktion</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 17:29:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/224399.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Oct 2008 06:10:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 06:10:51 GMT]]></title><description><![CDATA[<p>hi leute,</p>
<p>ich habe ein problem mit einer callback funktion. Diese muss ja static sein, das problem ist, ich kann dieser kein object der klasse übergeben, weil ich die signatur der funktion nicht aendern darf, die callback function wird bei einer anderen funktion registriert.<br />
nun die frage darf man einen statischen pointer der klasse den this pointer zuweisen (von der klasse foo gibts nur eine instanz!) und dann ueber den statischen pointer auf die elemente der klasse zugreifen, der member i darf auch nicht statisch sein, sonst wärs ja leicht;)</p>
<p>bye</p>
<pre><code class="language-cpp">class foo
{
public:
	foo();
	static foo *ptr_foo;
	static void callback_function();
private:
	int i;
};

foo::foo()
{
	ptr_foo = this;
	i = 10;
}

void foo::callback_function()
{
	ptr_foo-&gt;i = 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1595986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595986</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Thu, 09 Oct 2008 06:10:51 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 06:28:08 GMT]]></title><description><![CDATA[<p>this nach void* casten und als parameter an die callback funktion übergeben. in der callback wieder zurückcasten, dann kannst du auf die member des objektes zugreifen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1595988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595988</guid><dc:creator><![CDATA[sothis_]]></dc:creator><pubDate>Thu, 09 Oct 2008 06:28:08 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 06:35:01 GMT]]></title><description><![CDATA[<p>ich darf die signatur der callback funktion nicht aendern! -&gt; geht also nicht:<br />
this nach void* casten und als parameter an die callback funktion übergeben</p>
<p>bye</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1595991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595991</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Thu, 09 Oct 2008 06:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 06:36:27 GMT]]></title><description><![CDATA[<p>signatur sieht so aus:</p>
<pre><code class="language-cpp">void foo::callback_function(BL_signal_t signal)
</code></pre>
<p>ich darf da keinen void* als param hinzufuegen;/</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1595992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1595992</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Thu, 09 Oct 2008 06:36:27 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 07:07:52 GMT]]></title><description><![CDATA[<p>Dein Ansatz funktioniert. Du musst nur sicherstellen, dass der Pointer wirklich vor Benutzung des Callbacks initialisiert wird. Und natürlich hast du ein Problem, sobald du doch mehr als eine Instanz von foo verwenden willst.</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1596008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596008</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Thu, 09 Oct 2008 07:07:52 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 08:01:37 GMT]]></title><description><![CDATA[<p>warum sagt der compiler dann:</p>
<pre><code class="language-cpp">undefined reference to `foo::ptr_foo'
</code></pre>
<p>bye</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1596042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596042</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Thu, 09 Oct 2008 08:01:37 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 08:03:03 GMT]]></title><description><![CDATA[<p>Weil die Definition von ptr_foo fehlt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1596044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596044</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Thu, 09 Oct 2008 08:03:03 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 11:11:32 GMT]]></title><description><![CDATA[<p>gibt ja hier:</p>
<pre><code class="language-cpp">class foo
{
public:
    static foo *ptr_foo;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1596197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596197</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Thu, 09 Oct 2008 11:11:32 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 11:15:48 GMT]]></title><description><![CDATA[<p>Das ist die Deklaration. Die Definition steht in der cpp-Datei und heißt <code>foo* foo::ptr_foo = NULL;</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1596198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596198</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Thu, 09 Oct 2008 11:15:48 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 11:33:32 GMT]]></title><description><![CDATA[<p>Ich würde das ganze mit Proxys machen</p>
<p>So in der Art:</p>
<pre><code class="language-cpp">class Foo
{
public:
    int foo(int iParam)
    {}
    static int fooProxy(int iParam,  void *pAdditionalData)
    {
        Foo *pFoo= reinterpret_cast&lt;Foo*&gt;(pAdditionalData);
        return(pFoo-&gt;foo(iParam));
    }
};

...

typedef int (*PFNFOOPARAM)(int, void *);

...

void Call(PFNFOOPARAM Fn, void *pParam)
{
    (*Fn)(3, pParam);
}

...

Foo test;

Call(&amp;Foo::fooProxy, &amp;test);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1596218</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596218</guid><dc:creator><![CDATA[Blaze]]></dc:creator><pubDate>Thu, 09 Oct 2008 11:33:32 GMT</pubDate></item><item><title><![CDATA[Reply to problem mit statischer callback funktion on Thu, 09 Oct 2008 12:16:49 GMT]]></title><description><![CDATA[<p>ist auch eine möglichkeit!</p>
<p>wie gesagt ich kann die signatur der callback funktion nicht aendern!</p>
<p>die muss so sein:</p>
<pre><code class="language-cpp">void callback_function(BL_signal_t signal);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1596252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1596252</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Thu, 09 Oct 2008 12:16:49 GMT</pubDate></item></channel></rss>