boost::bind and methods of managed classes

Hi, is there a easy way/workaround to use methods of managed classes with boost::bind? boost::signal<void (int value)> testSignal; public __gc class TestManagedClass { public: TestManagedClass() {testSignal.connect(boost:bind(???)); } void test(int i); }; how can I connect the TestManagedClass::test method of a instance of a TestManagedClass to the signal ? It seem already not be allowed to get the adress of the method &OpenGlTestGUI::testMethod (compile error c2843, vc++7.1). Are there any work arounds? Has anybody alread used boost::bind and boost::signal with managed classes? best regards, Vasco Lohrenscheit

Vasco Lohrenscheit wrote:
Hi,
is there a easy way/workaround to use methods of managed classes with boost::bind?
boost::signal<void (int value)> testSignal;
public __gc class TestManagedClass { public:
TestManagedClass() {testSignal.connect(boost:bind(???)); } void test(int i); };
how can I connect the TestManagedClass::test method of a instance of a TestManagedClass to the signal ?
The following code appears to work. Whether it qualifies as easy is another matter. #include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> #using <mscorlib.dll> #include <vcclr.h> boost::function<void (int value)> testSignal; public __gc class TestManagedClass { public: TestManagedClass(); void test( int i ) { std::cout << "TestManagedClass::test( " << i << " )\n"; } }; void TMC_test_helper( gcroot<TestManagedClass*> this_, int i ) { this_->test( i ); } TestManagedClass::TestManagedClass() { testSignal = boost::bind( TMC_test_helper, gcroot<TestManagedClass*>( this ), _1 ); } int main() { TestManagedClass * tmc = __gc new TestManagedClass; testSignal( 4 ); }

Thanks for the answers. So there is no other way to use boost::bind and managed classes together than wrapping the managed class/methods by hand? :-( sorry if offtopic: What about the coming standardized version of the C++/CLI binding? Will it work better together with all the nice c++/boost stuff?

Is there a reason you can't use events/delegates? They should be faster than boost::signal and boost::function On Wed, 19 Jan 2005 03:40:37 +0100, Vasco Lohrenscheit <valoh@krautgames.de> wrote:
Hi,
is there a easy way/workaround to use methods of managed classes with boost::bind?
boost::signal<void (int value)> testSignal;
public __gc class TestManagedClass { public:
TestManagedClass() {testSignal.connect(boost:bind(???)); } void test(int i); };
how can I connect the TestManagedClass::test method of a instance of a TestManagedClass to the signal ?
It seem already not be allowed to get the adress of the method &OpenGlTestGUI::testMethod (compile error c2843, vc++7.1). Are there any work arounds? Has anybody alread used boost::bind and boost::signal with managed classes?
best regards,
Vasco Lohrenscheit
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Cory Nelson http://www.int64.org

At 18:41 19.01.2005, you wrote:
Is there a reason you can't use events/delegates? They should be faster than boost::signal and boost::function
Yes, I want to have a clean seperation between pure ISO c++(+boost) and managed c++. I use boost::signal, boost::method and boost::bind in my pure c++ modules where the main parts of my application are implemented. Managed c++ I only use for the gui with Windows.Forms. Therefore I want to bind the gui directly as possible to the pure c++ modules and don't want to pollute my application part with nonstandard c++. So using events/delegates everywhere is no alternative, plus till now I prefer boost::bind over them (parameter swizzling and default parameters which events/delegates afaik don't support). btw: Have you any links supporting your events/delegates faster then boost::signal/boost:function statement? How much faster are they?
participants (3)
-
Cory Nelson
-
Peter Dimov
-
Vasco Lohrenscheit