提升线程中出现错误"expression cannot be used as a function"?

Error "expression cannot be used as a function" in boost thread?

本文关键字:used be as function cannot expression 线程 错误      更新时间:2023-10-16

我在OpenSUSE和Boost 1.55上使用QT-Creator。生成所需的所有二进制文件。

该程序很简单,可以测试Boost线程的功能。只声明一个线程。

当构建程序时,我有以下错误

/home/esys/Documents/Boost/headers/boost/thread/detail/thread.hpp:117: error: expression cannot be used as a function
                 f();
                 ^

在thread.hpp中是这样的:

void run()
        {
            f();// line 117
        }
    private:
        F f;
    };

我对此感到很困惑,因为问题似乎是标题本身的代码而不是构建设置的东西!

如何解决这个问题?当然,我可以改变到另一个Boost版本,但我有点好奇这个错误。这是Boost库,伙计们!

我可以重现你的问题,你的线程声明:

boost::thread *p = new boost::thread("thread1");

无效:构造函数需要一个可调用对象(如functor),而不是string。您应该查看boost文档以获取更多信息。

(错误消息实际上是相当明确的:它告诉你你的表达式_字符串"thread1" _是不可调用的)

注意:

考虑std::thread作为boost::thread的替代品,如果你的编译器支持c++ 11。

相关文章: