【发布时间】:2018-07-18 20:06:15
【问题描述】:
我有使用的 C++ 代码
int nthreads = thread::hardware_concurrency();
当我尝试在某些计算机上构建我的应用程序时,我收到错误消息
error: 'thread' has not been declared
我不问如何解决错误。我更感兴趣的是是否有一个特殊的“守卫”,我可以使用它来简单地通过预处理器删除代码行,例如在我可以使用的 OpenMP 中:
#ifdef _OPENMP
...
#endif
【问题讨论】:
-
您问的问题对吗?听起来像XY problem。解决错误比尝试检测何时需要避免它更好。
-
"error: 'thread' has not been declared" - 你记得使用
#include <thread>吗?并且可能还有using namespace std;或更好的using std::thread;,因为您没有完全将hardware_concurrency()视为std::thread::hardware_concurrency(),仅作为thread::hardware_concurrency()
标签: c++ multithreading header c-preprocessor