
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 ); }