2016-11-07 46 views
0

一切工作和編譯很好,直到我#include <unistd.h>(這是我的CPP單修改),其完全地打破了一切:C++如果<unistd.h>奇怪的編譯錯誤,包括

test.cpp:173:33: error: no matching function for call to ‘std::thread::thread(, int, int, int)’ std::thread t1(read, 1, 0, 3), ^test.cpp:173:33: note: candidates are: In file included from test.cpp:6:0: /usr/include/c++/4.8/thread:133:7: note: template std::thread::thread(_Callable&&, _Args&& ...) thread(_Callable&& __f, _Args&&... __args)

[200 more similar lines]

沒有#include <unistd.h>一切工作和編譯,但我需要它爲https://stackoverflow.com/a/6856689/1879409

注:我之前通過apt-get安裝ncurses,也許這打破了我的環境?

+0

看起來你的'read'已經超載了:http://pubs.opengroup.org/onlinepubs/7908799/xsh/read.html – krzaq

+3

聽起來像''給全局命名空間增加了一個'read'函數。你用'std :: thread t1(read,1,0,3)'使用了什麼'read'函數? – NathanOliver

+5

@OP在編輯錯誤消息時不會注意到代碼塊很難閱讀,並且會從消息中刪除信息。例如,<未解析的重載函數類型>被刪除,因爲它被視爲HTML標記。 – NathanOliver

回答

1

這裏:

std::thread t1(read, 1, 0, 3) 

你一個函數指針傳遞給函數readstd::thread構造。

unistd.h聲明函數:ssize_t read(int, void *, size_t)

從錯誤消息中可以看出,您有read函數的過載。包含unistd.h之前使用的那個與unistd.h聲明的不一樣。重載函數不能隱式轉換爲函數指針,因爲編譯器無法知道您打算使用哪個函數。

您可以顯式地將標識符轉換爲正確類型的函數指針以解決歧義。