<?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 boost bind und member Funktionen mit variabler Anyahl von Argumenten]]></title><description><![CDATA[<p>Hallo, ich habe folgenden Quellcode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstdio&gt;
#include &lt;cstdarg&gt;

#include &lt;boost/bind.hpp&gt;
#include &lt;boost/function.hpp&gt;

class printfClass {
  public:
    int printf(const char* format, ...) {
    std::va_list args;
    va_start(args, format);
    int r = std::vprintf(format, args);
    va_end(args);
    return r; 
  }
};

int main(int argc, char **argv) {
   boost::function&lt;int (const char*)&gt; printWrapper = boost::bind&lt;int&gt;(std::printf, &quot;printWrapper: %s&quot;, _1); // geht
   printWrapper(&quot;Hello World&quot;);

   printfClass pr;
   boost::function&lt;int (const char*)&gt; printClassWrapper = boost::bind&lt;int&gt;(&amp;printfClass::printf, &amp;pr, &quot;printClassWrapper: %s&quot;, _1); //geht nicht
   printClassWrapper(&quot;Hello World&quot;);
}
</code></pre>
<p>Wie den Kommentaren zu entnehmen ist, geht der erste boost bind Aufruf mit std::printf als freistehende Funktion, während der zweite bind Aufruf mit printf als member Funktion in einer Klasse gekapselt nicht geht. Was ist falsch an meinen Quellcode?</p>
<p>Fehlermeldung ist (Compiler: g++ 4.5 unter Ubuntu 11.04):</p>
<pre><code>In file included from /usr/include/boost/bind.hpp:22:0,
                 from /home/rust/projects/boostBindTest/main.cpp:5:
/usr/include/boost/bind/bind.hpp: In member function ‘R boost::_bi::list3&lt;A1, A2, A3&gt;::operator()(boost::_bi::type&lt;R&gt;, F&amp;, A&amp;, long int) [with R = int, F = int (printfClass::*)(const char*, ...), A = boost::_bi::list1&lt;const char*&amp;&gt;, A1 = boost::_bi::value&lt;printfClass*&gt;, A2 = boost::_bi::value&lt;const char*&gt;, A3 = boost::arg&lt;1&gt;]’:
/usr/include/boost/bind/bind_template.hpp:32:59:   instantiated from ‘boost::_bi::bind_t&lt;R, F, L&gt;::result_type boost::_bi::bind_t&lt;R, F, L&gt;::operator()(A1&amp;) [with A1 = const char*, R = int, F = int (printfClass::*)(const char*, ...), L = boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt;, boost::_bi::bind_t&lt;R, F, L&gt;::result_type = int]’
/usr/include/boost/function/function_template.hpp:132:42:   instantiated from ‘static R boost::detail::function::function_obj_invoker1&lt;FunctionObj, R, T0&gt;::invoke(boost::detail::function::function_buffer&amp;, T0) [with FunctionObj = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*]’
/usr/include/boost/function/function_template.hpp:913:60:   instantiated from ‘void boost::function1&lt;R, T1&gt;::assign_to(Functor) [with Functor = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*]’
/usr/include/boost/function/function_template.hpp:722:7:   instantiated from ‘boost::function1&lt;R, T1&gt;::function1(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’
/usr/include/boost/function/function_template.hpp:1064:16:   instantiated from ‘boost::function&lt;R(T0)&gt;::function(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’
/home/rust/projects/boostBindTest/main.cpp:24:130:   instantiated from here
/usr/include/boost/bind/bind.hpp:382:98: error: no match for call to ‘(boost::_mfi::dm&lt;int(const char*, ...), printfClass&gt;) (printfClass*&amp;, const char*&amp;, const char*&amp;)’
/usr/include/boost/bind/mem_fn.hpp:340:9: note: candidates are: R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(T*) const [with R = int(const char*, ...), T = printfClass]
/usr/include/boost/bind/mem_fn.hpp:345:15: note:                 const R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(const T*) const [with R = int(const char*, ...), T = printfClass]
/usr/include/boost/bind/mem_fn.hpp:357:9: note:                 R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(T&amp;) const [with R = int(const char*, ...), T = printfClass]
/usr/include/boost/bind/mem_fn.hpp:362:15: note:                 const R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(const T&amp;) const [with R = int(const char*, ...), T = printfClass]
make[2]: *** [CMakeFiles/boostbindtest.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/boostbindtest.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/294368/problem-mit-boost-bind-und-member-funktionen-mit-variabler-anyahl-von-argumenten</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 23:30:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/294368.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 24 Oct 2011 10:20:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit boost bind und member Funktionen mit variabler Anyahl von Argumenten on Mon, 24 Oct 2011 10:20:17 GMT]]></title><description><![CDATA[<p>Hallo, ich habe folgenden Quellcode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cstdio&gt;
#include &lt;cstdarg&gt;

#include &lt;boost/bind.hpp&gt;
#include &lt;boost/function.hpp&gt;

class printfClass {
  public:
    int printf(const char* format, ...) {
    std::va_list args;
    va_start(args, format);
    int r = std::vprintf(format, args);
    va_end(args);
    return r; 
  }
};

int main(int argc, char **argv) {
   boost::function&lt;int (const char*)&gt; printWrapper = boost::bind&lt;int&gt;(std::printf, &quot;printWrapper: %s&quot;, _1); // geht
   printWrapper(&quot;Hello World&quot;);

   printfClass pr;
   boost::function&lt;int (const char*)&gt; printClassWrapper = boost::bind&lt;int&gt;(&amp;printfClass::printf, &amp;pr, &quot;printClassWrapper: %s&quot;, _1); //geht nicht
   printClassWrapper(&quot;Hello World&quot;);
}
</code></pre>
<p>Wie den Kommentaren zu entnehmen ist, geht der erste boost bind Aufruf mit std::printf als freistehende Funktion, während der zweite bind Aufruf mit printf als member Funktion in einer Klasse gekapselt nicht geht. Was ist falsch an meinen Quellcode?</p>
<p>Fehlermeldung ist (Compiler: g++ 4.5 unter Ubuntu 11.04):</p>
<pre><code>In file included from /usr/include/boost/bind.hpp:22:0,
                 from /home/rust/projects/boostBindTest/main.cpp:5:
/usr/include/boost/bind/bind.hpp: In member function ‘R boost::_bi::list3&lt;A1, A2, A3&gt;::operator()(boost::_bi::type&lt;R&gt;, F&amp;, A&amp;, long int) [with R = int, F = int (printfClass::*)(const char*, ...), A = boost::_bi::list1&lt;const char*&amp;&gt;, A1 = boost::_bi::value&lt;printfClass*&gt;, A2 = boost::_bi::value&lt;const char*&gt;, A3 = boost::arg&lt;1&gt;]’:
/usr/include/boost/bind/bind_template.hpp:32:59:   instantiated from ‘boost::_bi::bind_t&lt;R, F, L&gt;::result_type boost::_bi::bind_t&lt;R, F, L&gt;::operator()(A1&amp;) [with A1 = const char*, R = int, F = int (printfClass::*)(const char*, ...), L = boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt;, boost::_bi::bind_t&lt;R, F, L&gt;::result_type = int]’
/usr/include/boost/function/function_template.hpp:132:42:   instantiated from ‘static R boost::detail::function::function_obj_invoker1&lt;FunctionObj, R, T0&gt;::invoke(boost::detail::function::function_buffer&amp;, T0) [with FunctionObj = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*]’
/usr/include/boost/function/function_template.hpp:913:60:   instantiated from ‘void boost::function1&lt;R, T1&gt;::assign_to(Functor) [with Functor = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*]’
/usr/include/boost/function/function_template.hpp:722:7:   instantiated from ‘boost::function1&lt;R, T1&gt;::function1(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’
/usr/include/boost/function/function_template.hpp:1064:16:   instantiated from ‘boost::function&lt;R(T0)&gt;::function(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::_bi::bind_t&lt;int, int (printfClass::*)(const char*, ...), boost::_bi::list3&lt;boost::_bi::value&lt;printfClass*&gt;, boost::_bi::value&lt;const char*&gt;, boost::arg&lt;1&gt; &gt; &gt;, R = int, T0 = const char*, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’
/home/rust/projects/boostBindTest/main.cpp:24:130:   instantiated from here
/usr/include/boost/bind/bind.hpp:382:98: error: no match for call to ‘(boost::_mfi::dm&lt;int(const char*, ...), printfClass&gt;) (printfClass*&amp;, const char*&amp;, const char*&amp;)’
/usr/include/boost/bind/mem_fn.hpp:340:9: note: candidates are: R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(T*) const [with R = int(const char*, ...), T = printfClass]
/usr/include/boost/bind/mem_fn.hpp:345:15: note:                 const R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(const T*) const [with R = int(const char*, ...), T = printfClass]
/usr/include/boost/bind/mem_fn.hpp:357:9: note:                 R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(T&amp;) const [with R = int(const char*, ...), T = printfClass]
/usr/include/boost/bind/mem_fn.hpp:362:15: note:                 const R&amp; boost::_mfi::dm&lt;R, T&gt;::operator()(const T&amp;) const [with R = int(const char*, ...), T = printfClass]
make[2]: *** [CMakeFiles/boostbindtest.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/boostbindtest.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2135024</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2135024</guid><dc:creator><![CDATA[299792458]]></dc:creator><pubDate>Mon, 24 Oct 2011 10:20:17 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost bind und member Funktionen mit variabler Anyahl von Argumenten on Mon, 24 Oct 2011 12:22:36 GMT]]></title><description><![CDATA[<p>299792458 schrieb:</p>
<blockquote>
<p>Was ist falsch an meinen Quellcode?</p>
</blockquote>
<p>Du versuchst, oldscool C-Mittel (Ellipse und va_args) mit modernen C++-Mitteln zu verknüpfen. Was willst du damit erreichen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2135078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2135078</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 24 Oct 2011 12:22:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost bind und member Funktionen mit variabler Anyahl von Argumenten on Mon, 24 Oct 2011 13:38:46 GMT]]></title><description><![CDATA[<p>Ich verwende JNI um von Java-Code auf eine C-Bibliothek zu zugreifen.<br />
JNI ist reines C mit einem ganz dünnen C++-Wrapper drumherum. Ich selber habe eine C++-Bibliothek geschrieben, die mittels xcb-xv auf XV zugreift. Für diese Bibliothek möchte ich jetzt eine Anbindung an Java schreiben. Meine Bibliothek bietet es an einen Callback zu registrieren, der falls sich ein Wert in XV verändert hat, aufgerufen wird (simples Eventhandling). Diese Funktion wird in einem boost::function Objekt gekapselt. Für meine Java-Anbindung soll statt einer normalen C++-Funktion eine Java-Funktion aufgerufen werden. Java-Funktionen werden in JNI mittels einer Helperfunktion aufgerufen, die das Javaobjekt und die methodID als feste Parameter erwartet, danach folgt eine variable Anzahl von Argumenten, die an die Java Funktion übergeben werden. Ich möchte jetzt die JNI spezifischen Sachen an die Funktion binden, damit ich eine Funktion erhalte, die ich meiner C++ Bibliothek übergeben kann.<br />
Das heißt aus</p>
<pre><code class="language-cpp">env-&gt;CallVoidMethod(listener, changeNotifyListenerChangeOccurredMethodID, arg1, arg2, arg3)
</code></pre>
<p>soll</p>
<pre><code class="language-cpp">helperFunction(arg1, arg2, arg3)
</code></pre>
<p>werden. Damit ich für helperFunction dann eine boost::function Objekt erzeugen kann, wie es meine C++-Bibliothek erwartet. Hier die Signatur der entsprechen Funktion aus meiner Bibliothek:</p>
<pre><code class="language-cpp">void registerChangeNotifyFunction(boost::function&lt;void (std::size_t adaptorIndex, std::size_t attributeIndex, int32_t value)&gt; func);
</code></pre>
<p>Der boost::bind Aufruf sieht so aus:</p>
<pre><code class="language-cpp">boost::bind&lt;void&gt;(&amp;JNIEnv::CallVoidMethod, env, listener, changeNotifyListenerChangeOccurredMethodID, _1, _2, _3)
</code></pre>
<p>Das hat allerdings nicht funktioniert(ließ sich nicht kompilieren), also habe ich um festzustellen wo das Problem liegt, versucht ein minimales Programm zu schreiben, wo dasselbe Problem auftritt. Dieses minimale Code-Beispiel habe ich dann hier gepostet. D.h der in meinen ersten Post gezeigte Quellcode verdeutlicht nur mein Problem, hat damit aber sonst eigentlich nicht viel zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2135130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2135130</guid><dc:creator><![CDATA[299792458]]></dc:creator><pubDate>Mon, 24 Oct 2011 13:38:46 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost bind und member Funktionen mit variabler Anyahl von Argumenten on Mon, 24 Oct 2011 13:44:15 GMT]]></title><description><![CDATA[<p>Im JNI gibt es für jede Ellipsenfunktion auch eine, die va_list enggegennimmt. zum Beispiel kann man</p>
<pre><code class="language-cpp">va_list args;

// va_start(args, yadda yadda);

env-&gt;CallVoidMethodV(listener, changeNotifyListenerChangeOccurredMethodID, args);
//                 ^-- V hier.

va_end(args);
</code></pre>
<p>schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2135132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2135132</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Mon, 24 Oct 2011 13:44:15 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost bind und member Funktionen mit variabler Anyahl von Argumenten on Mon, 24 Oct 2011 13:56:43 GMT]]></title><description><![CDATA[<p>seldon schrieb:</p>
<blockquote>
<p>Im JNI gibt es für jede Ellipsenfunktion auch eine, die va_list enggegennimmt. zum Beispiel kann man</p>
<pre><code class="language-cpp">va_list args;

// va_start(args, yadda yadda);

env-&gt;CallVoidMethodV(listener, changeNotifyListenerChangeOccurredMethodID, args);
//                 ^-- V hier.

va_end(args);
</code></pre>
<p>schreiben.</p>
</blockquote>
<p>Entschuldige, aber ich verstehe nicht ganz wie mir das helfen soll. Ich hätte gerne die Möglichkeit, dass meine C++-Bibliothek eine Java-Funktion als Callback aufrufen kann. Meine C++-Bibliothek beinhaltet eine Klasse XVAttributeManager mit einer Methode registerChangeNotifyFunction:</p>
<pre><code class="language-cpp">class XVAttributeManager : boost::noncopyable {
public:
   // you can register a function, which will be called from lookForChanges, waitForChanges or observeChanges in case the value of an attribute has changed
    void registerChangeNotifyFunction(boost::function&lt;void (std::size_t adaptorIndex, std::size_t attributeIndex, int32_t value)&gt; func);

   // Rest weg gelassen
};
</code></pre>
<p>Damit ich mittels dieser Methode eine Java-Funktion als Callback setzen kann, muss ich es schaffen den ganzen JNI-Krams(jobject und jmethodID) an env-&gt;CallVoidMethod() zu binden, sodass eine Funktion mit der Signatur:</p>
<pre><code class="language-cpp">void wrappedJNICallVoidMethodFunction(std::size_t, std::size_t, int32_t)
</code></pre>
<p>herauskommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2135138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2135138</guid><dc:creator><![CDATA[299792458]]></dc:creator><pubDate>Mon, 24 Oct 2011 13:56:43 GMT</pubDate></item></channel></rss>