2012-07-09 36 views
1

此代碼不能編譯,使用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它編譯。我怎樣才能解決這個問題?

回答

1

你的第二個參數(boost::filesystem::native)是錯誤的。 boost::filesystem::path只需doesn’t have a constructor它採取這個參數 - 離開它,代碼編譯。

實際上,boost::filesystem::native函數,並且以您嘗試的方式使用它是沒有意義的。此外,如果MSVC編譯這段代碼,那是一個明確的錯誤(它使用從函數指針到void*的隱式轉換,這根據標準不存在)。

相關問題