【发布时间】:2021-11-08 08:25:47
【问题描述】:
我有这个代码:
#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 中使用了该功能而发生这种情况。我也不知道为什么会这样。
【问题讨论】:
-
“当我调用 getter 函数时”是什么意思?显示的一行代码没有携带任何有用的信息。它出现在哪里?一些功能?什么方法?您能否按照 Stackoverflow 的说明创建一个每个人都可以剪切/粘贴的minimal reproducible example,完全如图所示 到一个空文件中,然后尝试编译并重现您的编译错误?
-
@SamVarshavchik 我编辑我的问题
标签: c++ c++11 static c++17 c++14