文件系统::p ath 构造函数调用失败



这段代码不能编译,使用 Boost 1.48 和 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

错误消息:

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*]’

在 MSVC 下,它进行编译。我该如何解决这个问题?

你的第二个参数(boost::filesystem::native(是错误的。 boost::filesystem::path根本没有一个接受这个参数的构造函数 - 将其关闭,代码编译。

事实上,boost::filesystem::native是一个函数,以您尝试的方式使用它毫无意义。此外,如果 MSVC 编译此代码,这是一个明确的错误(它使用从函数指针到 void* 的隐式转换,根据标准不存在(。

最新更新