尝试编译时出现 Boost 线程 c2064 错误

Boost thread c2064 error when trying to compile

本文关键字:Boost 线程 c2064 错误 编译      更新时间:2023-10-16

我对堆栈溢出很陌生,实际上这是我的第一篇文章,所以大家好。因此,让我们进入正题。使用提升库线程版本 1.54.0使用 VS2010 32 位 - 专业版我已经为提升线程构建了库,在 VS C++设置中不使用预编译标头,将库链接到项目,这是代码

    #include <boostthreadthread_only.hpp>
#include <iostream>
#include <conio.h>
#pragma comment(lib, "libboost_thread-vc100-mt-gd-1_54.lib")
#define BOOST_LIB_NAME libboost_thread-vc100-mt-gd-1_54.lib

struct callable
{
     void blah();
};
void callable::blah()
{
    std::cout << "Threading test !n";
}
boost::thread createThread()
{
    callable x;
    return boost::thread(x);
}
int main()
{
    createThread();
    _getch();
    return 0;
}

在所有这些之后,我收到此错误

Error   1   error C2064: term does not evaluate to a function taking 0 arguments    ....boost_1_54_0boostthreaddetailthread.hpp   117 1   BoostTrial

你能帮我让这个例子工作吗?我使用此示例的原因是因为我有另一个应用程序,该应用程序的设置方式完全相同,但由于此错误而无法正常工作:-(我的目标是让多线程工作,然后我可以从那里获取它。谢谢你的时间。

您需要在callable中实现operator()

不要忘记join()detach()线程以防止程序异常终止。

有关更多示例,请参阅boost::thread教程。

#include <boostthreadthread_only.hpp>
#include <iostream>
#pragma comment(lib, "libboost_thread-vc100-mt-gd-1_54.lib")
using namespace boost;
struct callable
{
    void operator()()
    {
        std::cout << "Threading test !n";
    }
};

boost::thread createThread()
{
    callable x;
    return boost::thread(x);
}
int main()
{
    boost::thread th = createThread();
    th.join();
}

示例与std::thread ;