Hello guys,
I am using Boost Coroutines but I would like to use them in a Objected-Oriented way. So, I tried to rewrite parallel.cpp (boost/libs/coroutine/example) using the example functions like class methods, but it did not work. This is my code, anybody can help me?
My code:
typedef boost::coroutines::coroutine< void() > coroutine_t;
class Abc{
public:
void first( coroutine_t::caller_type & self)
{
std::cout << "started first! ";
for ( int i = 0; i < 10; ++i)
{
self();
std::cout << "a" << i;
}
}
void second( coroutine_t::caller_type & self)
{
std::cout << "started second! ";
for ( int i = 0; i < 10; ++i)
{
self();
std::cout << "b" << i;
}
}
void third(){
coroutine_t c1( boost::bind( first, _1) );
coroutine_t c2( boost::bind( second, _1) );
while ( c1 && c2) {
c1();
std::cout << " ";
c2();
std::cout << " ";
}
}
};
int main( int argc, char * argv[])
{
Abc* myabc = new Abc();
myabc->third();
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
Thank you,
Van