C++11 thread 错误:no type named ‘t

2020-12-05  本文已影响0人  喝橙橙橙汁儿

最近用C++11,在用thread()传对象参数时,也就是调用其他类的方法作为线程执行函数,该传入的执行函数有两个引用参数

线程执行函数:void handle(int &sock_fd, ros::Publisher &pub);

出错的调用方式:

using namespace std;

test handler;

std::thread recv_thread(&test::handle, &handler, ref(this->sock_recv_fd), pub);//其中pub在传入前已经是一个引用

提示我 no type named ‘type’  一堆错误。查阅过解答,主要是stack over flow 上的回答,一堆英文。我直接说解决方式吧

std::thread recv_thread(&test::handle, &handler, ref(this->sock_recv_fd), ref(pub));//给pub也加上ref

是的,传引用即使你的类型已经是引用,还是得加ref(),否则编译器不认。

上一篇 下一篇

猜你喜欢

热点阅读