0

Everything worked and compiled fine until I #include <unistd.h> (this is the single modification in my cpp) which completly breaks everything:

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]

Without #include <unistd.h> everything works and compiles but I need it for https://stackoverflow.com/a/6856689/1879409

Note: I installed ncurses before via apt-get, maybe this broke my env?

Community
  • 1
  • 1
Pali
  • 1,337
  • 1
  • 14
  • 40
  • It looks like your `read` has been overloaded: http://pubs.opengroup.org/onlinepubs/7908799/xsh/read.html – krzaq Nov 07 '16 at 12:55
  • 3
    sounds like `` adds a `read` function to the global namespace. What `read` function are you using with `std::thread t1(read, 1, 0, 3)`? – NathanOliver Nov 07 '16 at 12:55
  • 5
    @OP do note when you edit the error message to not be a code block it is hard to read and it removes information from the message. For example ` is removed as it is treated as a HTML tag. – NathanOliver Nov 07 '16 at 12:58
  • I suppose is a method conflict going on into your code when including unistd – Ispas Claudiu Nov 07 '16 at 13:00
  • @krzaq you were right thank you very much – Pali Nov 07 '16 at 13:12

1 Answers1

1

Here:

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

You pass a function pointer to the function read to the constructor of std::thread.

unistd.h declares the function: ssize_t read(int, void *, size_t).

As can be seen from the error message, you have overloads for the read function. The one that you used before including unistd.h is not the same as what unistd.h declares. An overloaded function cannot be implicitly converted into a function pointer, because the compiler cannot know which read function you intended to use.

You can explicitly cast the identifier to a function pointer of correct type to resolve the ambiguity.

eerorika
  • 232,697
  • 12
  • 197
  • 326