The following code compiles without warnings or errors: (I am using clang 3.8 in -std=c++14 mode):
typedef boost::coroutines2::coroutine<int> coro_t;
coro_t::push_type sink(
[](coro_t::pull_type& source){
while(source){
std::cout << source.get() << " ";
source();
}
});
However, if I place the same code inside a class:
class EnclosingClass {
coro_t::push_type sink(
[](coro_t::pull_type& source){
while(source){
std::cout << source.get() << " ";
source();
}
});
};
I get the following errors:
test.cpp:13:26: error: C++ requires a type specifier for all declarations
coro_t::push_type sink([](coro_t::pull_type &source) {
^
test.cpp:13:26: error: 'type name' declared as array of functions of type 'int (coro_t::pull_type &)' (aka 'int (pull_coroutine<int> &)')
test.cpp:13:56: error: expected ')'
coro_t::push_type sink([](coro_t::pull_type &source) {
^
test.cpp:13:25: note: to match this '('
coro_t::push_type sink([](coro_t::pull_type &source) {
^
How can I have a boost::coroutine2 as a class member?
I was expecting code in the global context to also work OK inside a class, but it doesn't. Is there an interesting reason why?
Aucun commentaire:
Enregistrer un commentaire