试图构造的std ::线程时奇怪的编译器错误:

问题描述 投票:0回答:1

下面的程序将失败,并g++ -std=c++11 -Wall -Werror test.cpp -o test.o编译:

#include <thread>
using namespace std;

void fill(int n) {
    return;
}

int main() {
    thread test(fill, 5);
}
test.cpp:9:12: error: no matching constructor for initialization of 'std::__1::thread'
    thread test(fill, 5);
           ^    ~~~~~~~

是不是因为fill与来自std::fill #include <algorithm>发生冲突?我没有列入这一点,但我想可能<thread>过。

改变我的函数名fillie(或任何其他相当多),允许它正确编译不链接pthread

我问,因为这是一个奇怪的编译器错误消息,并且还意味着线程构造函数不能消除歧义,我使用基于参数,函数(排序是有意义的,但希望确认)。

c++ c++11 stdthread
1个回答
5
投票

是的,问题是,因为它不知道fill是否std::fill或全局fill功能。

要解决这个问题的方法之一是写::fill明确地使用全球性的。

© www.soinside.com 2019 - 2024. All rights reserved.