Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-01-19 07:10:26


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net