gpt4 book ai didi

c++ - 谷歌测试中的使用线程

转载 作者:行者123 更新时间:2023-11-28 05:53:04 28 4
gpt4 key购买 nike

我想创建一些测试来检查我的应用程序中的多线程。我使用谷歌测试框架。我的以下代码未编译时出现错误消息 error: invalid use of non-static member function

TEST_F( tc, t ) {
std::thread thread1 ( f1, p1 );
std::thread thread2 ( f2, p2 );
thread1.join();
thread2.join();
}

我使用 GCC 5.2.1 进行编译。

你能指点我修复它吗?

最佳答案

您需要使用 std::bind 告诉 std::thread f1 和 f2 是您的测试夹具的方法:

TEST_F( tc, t ) {
std::thread thread1(std::bind(&tc::f1, this, p1));
std::thread thread2(std::bind(&tc::f2, this, p2));
thread1.join();
thread2.join();
}

关于c++ - 谷歌测试中的使用线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34807879/

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