Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: ‘xx’ is not a member of ‘xxx {aka xxx}’ #18

Closed
aengusjiang opened this issue Sep 3, 2020 · 2 comments
Closed

error: ‘xx’ is not a member of ‘xxx {aka xxx}’ #18

aengusjiang opened this issue Sep 3, 2020 · 2 comments
Assignees
Labels

Comments

@aengusjiang
Copy link

使用task action,写一个自定义的action 类
class ThenTaskAction1
{
public:
ThenTaskAction1(){}

int operator()(void*)
{
    return 0;
}

private:
};

然后调用copp_task的then方法:
using simple_task_t = cotask::task<>;
auto co_task = simple_task_t::create(
{
});
if (nullptr != co_task)
{
co_task->start();
//auto then_ptr1 = co_task->then(ThenTaskAction1()); // build OK

       ThenTaskAction1 tmp;
        auto then_ptr2 = co_task->then(tmp);                                 // 错误: ThenTaskAction1没有operator()成员 
    }
    else
        printf("error create coroutine %d\n", i);

我这边跟踪了一下原因是后面一种调用在模板参数类型是ThenTaskAction1&, 然而前者解释模板参数类型是ThenTaskAction1
于是我这边的解决方式是
在task_actions.h:91行改成
virtual int operator()(void *priv_data) {
return detail::task_action_functor_check::call(&std::remove_reference<value_type>::type::operator(), functor_, priv_data);
}
去掉了引用

看一下大神有什么好的解决方式或者有什么见解

@owent
Copy link
Owner

owent commented Sep 3, 2020

@aengusjiang 感谢反馈。这里确实是有个问题。开启右值的分支里对类型的推断不支持非右值。

这里建议action传入的时候move一下,否则即便修复了也是会拷贝构造来复制对象,可能会开销高。最初让这种情况编译不过是为了防止不小心使用了高开销的操作。

不过这确实导致两个分支的代码不能无缝切换,我明天处理下这个适配。需要修改构造流程,否则生命周期的维护有问题。

@owent
Copy link
Owner

owent commented Sep 4, 2020

@aengusjiang Fixed in 1.3.2

@owent owent closed this as completed Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants