Alex F
Alex F

Reputation: 43311

filesystem::path constructor call fails

This code does not compile, using Boost 1.48 and GCC:

// const char* left, const char* right

boost::filesystem::path p =  boost::filesystem::absolute( 
   boost::filesystem::path(right, boost::filesystem::native),     // line 314
   boost::filesystem::path(left, boost::filesystem::native) );    // line 315

Error messages:

LoggerImplementation.cpp|314|error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘void*’
LoggerImplementation.cpp|314|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>, void>::type*) [with Source = const char*]’
LoggerImplementation.cpp|315|error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘void*’
LoggerImplementation.cpp|315|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>, void>::type*) [with Source = const char*]’

Under MSVC it compiles. How can I fix this?

Upvotes: 1

Views: 1167

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545518

Your second argument (boost::filesystem::native) is wrong. boost::filesystem::path simply doesn’t have a constructor which takes this argument – leave it off and the code compiles.

In fact, boost::filesystem::native is a function, and using it in the manner you tried makes no sense. Furthermore, if MSVC compiles this code, that’s a definitive bug (it is using an implicit conversion from a function pointer to void*, which doesn’t exist according to the standard).

Upvotes: 1

Related Questions