Boost logo

Boost Users :

Subject: Re: [Boost-users] invalid conversion from 'bool
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-07-19 02:04:29


> Dear Advanced c/g++ on boost programers:
>
> I have copied and testd a simple (Copy a file with Boost) program from page 372, Example10-10, book(C++ cookbook)
> but I got compile error
> -----------------------------
> eric_at_eric-laptop:~/cppcookbook/ch10$ g++ Example10-10.cpp
> Example10-10.cpp: In function ‘int main(int, char**)’:
> Example10-10.cpp:17:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’
> Example10-10.cpp:17:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’
> Example10-10.cpp:18:47: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘boost::enable_if_c<true, void>::type*’
> Example10-10.cpp:18:47: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type*) [with Source = char*, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<Source>::type> >::type = void]’
> Example10-10.cpp:18:48: error: expected ‘)’ before ‘;’ token
> -----------------------------
> This is my program, you can download and test by your self from
> http://examples.oreilly.com/9780596007614/
> -----------------------------------------------------
> // Example 10-10. Copying a file with Boost
> #include <iostream>
> #include <string>
> #include <boost/filesystem/operations.hpp>
> #include <boost/filesystem/fstream.hpp>
> #include <boost/filesystem/path.hpp>
>
> using namespace std;
> using namespace boost::filesystem;
>
> int main(int argc, char** argv) {
>
> // Parameter checking...
>
> try {
> // Turn the args into absolute paths using native formatting
> path src = complete(path(argv[1], native));
> path dst = complete(path(argv[2], native);
> copy_file(src, dst);
> }
> catch (exception& e) {
> cerr << e.what() << endl;
> }
>
> return(EXIT_SUCCESS);
> }

The Boost Filesystem library underwent an upgrade, from v2 in Boost
1.45 and before, to v3 in Boost 1.46 and after. This was a breaking
change, so code that worked with v2 won't necessarily work with v3.
 
The code from the C++ Cookbook works well with Filesystem v2, but
not with Filesystem v3.
 
You can either:
 
1) Compile your code with Filesystem v2 (it's still around in Boost
1.46, it's just not the default). You can do this by adding
 
#define BOOST_FILESYSTEM_VERSION 2
 
at the top of your file, or passing the flag
 
-DBOOST_FILESYSTEM_VERSION=2
 
to your compiler.
 
2) Correct the code to work with Filesystem v3, by removing the
second parameter ("native") from the path constructors.
 
If you are getting further errors after doing either of these steps,
you have a different (additional) problem and you'll need to post
the new errors for us to help you with it.
 
Regards,
Nate.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net