我有这个代码:
#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
. 我也不知道为什么会这样。
您需要将其更改为 _status.Available。您正在尝试引用 Status 结构,而不是该结构的实例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句