在 std::async 中使用的函数中调用我的 Struct 时调用没有对象参数的非静态成员函数

帕丽莎人力资源

我有这个代码:

#include <future>
#include <iostream>

struct Status
{
    std::string Available;
    std::string Connected;
    std::string DisConnected;
};

class Test
{
 public:
   Test();

   Status &status()
   {
       return _status;
   }
   void setStatus(const Status &newStatus)
   {
       _status = newStatus;
   }

   std::string show()
   {

       return Status::Available;
   }

private:
    Status _status ;
};



int main()
{

    Test tst;

    auto value= std::async([](std::string str) { return str;} ,tst.show());

    std::cout <<value.get();


    return 0;
}

当我编译它时,我收到此错误:

非法引用非静态成员 'Status::Available'

我不知道我应该如何解决这个问题,但它发生是因为我在std::async. 我也不知道为什么会这样。

在此处输入图片说明

日月12

您需要将其更改为 _status.Available。您正在尝试引用 Status 结构,而不是该结构的实例。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

std :: async与非静态成员函数

用std :: async调用模板成员函数

std :: async与重载函数

使用std :: async调用模板函数的正确方法是什么

在没有对象参数的情况下调用非静态成员函数,C ++节点

在没有对象参数的情况下调用非静态成员函数会发生错误

成员字段的成员函数上的 std::async

std :: async与成员函数,持有另一个成员函数作为参数

std::async 不会立即调用

并行 std::foreach 循环调用非静态类成员函数

“没有匹配的函数可以调用'async(std :: launch,<未解析的重载函数类型>,std :: string&)'”

为什么std :: async即使指定的std :: launch :: async标志也同步调用函数

是否保证为返回void的函数调用std :: async?

std::packaged_task<T> (Function Template) 是带有调用函数的 std::async (FT) 吗?

带有std :: async的模板函数

为std :: vector <struct>创建getter函数

没有对象就无法调用成员函数std :: string Sportist :: getIme()

std :: map <struct,int>我需要析构函数吗?

使用 std::function 在非指针对象上调用成员函数

是否可以在不调用 std async 的情况下使用阻塞析构函数创建 std 未来?

在主函数以外的函数中使用 std::async 时的作用域块

如何在成员函数内将函数及其参数传递给 std::async

C中的struct中使用的函数指针

std :: async过多参数

使用std :: find跨步,仅检查struct中的特定成员

在 React 中使用 async/await 时不会调用函数

从async.series调用的原型函数中使用“ this”

并非所有 std::packaged_tasks 都在 std::async 调用中执行

具有扩展的元组参数std :: invoke与std :: apply的调用成员函数