Hi, I am a new user of the boost libs, so sorry for the supid questions. I am running into a compilation error while trying to compile listing 2 and listing 3 from Bill Kempf's article at http://www.cuj.com/articles/2002/0205/0205a/0205a.htm, giving simple usage examples of boost threads. 1. When I compile listing 2, the compiler chokes on the lines boost::thread thrd1(count(1)); boost::thread thrd2(count(2)); with the errors listing2.C:27: no matching function for call to `count (int)' listing2.C:28: no matching function for call to `count (int)' As you can see in the listing online, count is defined as 'struct count{...}' Upon perusal of threah.hpp, I see that, indeed, the class thread constructor is looking for a function, not a struct or class as count is defined in this code. Am I missing something, or is the code in error? 2. In listing 2, I get the following errors when compiling: listing3.C:29: no matching function for call to `bind ({unknown type}, int)' listing3.C:31: no matching function for call to `bind ({unknown type}, int)' This is in response to the lines: boost::thread thrd1(boost::bind(&count, 1)); boost::thread thrd2(boost::bind(&count, 2)); Again, am I missing something or what? I have pasted the code directly from the source as provided online. TIA for your help Richard
In problem (2) in my previous email I cited code Listing 2, but this compilation error was actually generated by code Listing 3, as follows: // This program is identical to // listing2.cpp except that it // uses Boost.Bind to simplify // the creation of a thread that // takes data. #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <boost/bind.hpp> #include <iostream> boost::mutex io_mutex; void count(int id) { for (int i = 0; i < 10; ++i) { boost::mutex::scoped_lock lock(io_mutex); std::cout << id << ": " << i << std::endl; } } int main(int argc, char* argv[]) { boost::thread thrd1(boost::bind(&count, 1)); boost::thread thrd2(boost::bind(&count, 2)); thrd1.join(); thrd2.join(); return 0; } The errors are: listing3.C:29: no matching function for call to `bind ({unknown type}, int)' listing3.C:31: no matching function for call to `bind ({unknown type}, int)' Thanks [Non-text portions of this message have been removed]
El Fri, 31 May 2002 16:39:19 -0400 "Richard Fox" <rfox@sbsii.com> escribió:
In problem (2) in my previous email I cited code Listing 2, but this compilation error was actually generated by code Listing 3, as follows:
...
The errors are:
listing3.C:29: no matching function for call to `bind ({unknown type}, int)' listing3.C:31: no matching function for call to `bind ({unknown type}, int)'
Thanks
It works for me in gcc 3.0.4 Try to change the lines with bind to: boost::thread thrd1(boost::bind(count, 1)); boost::thread thrd2(boost::bind(count, 2)); it should work too. Regards, Raúl.
participants (3)
-
Raul Huertas Diaz
-
rgalek2002
-
Richard Fox