gpt4 book ai didi

C++ 可运行类

转载 作者:太空狗 更新时间:2023-10-29 21:05:56 25 4
gpt4 key购买 nike

我想从 Java 实现类似于接口(interface) Runnable 的东西。我尝试这样做:

class Runnable{
public:
void start(){
t = std::thread(&Runnable::run, this);
}
protected:
virtual void run(){
}
};

想法很简单。我想重载 run 方法,然后 start() 应该启动重载的方法。但是……它不起作用。

terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted

PS 我使用 dlopen 从动态库中加载了一个派生自 Runnable 的类实例。

最佳答案

此错误通常由 GCC 在命令行中忘记使用 -pthread 时产生。

关于C++ 可运行类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8631251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com