我这里有一些遗留代码,它们在 1.34.1 版本中使用了 boost::filesystem。我把它隔离成一个小测试程序:
#include <iostream>
#include <boost/filesystem/path.hpp>
int main()
{
// note the second parameter
boost::filesystem::path p( "/tmp/foo", boost::filesystem::native );
std::cout << p.string() << std::endl;
return 0;
}
当我尝试使用当前 (1.46.1) 版本的 Boost 编译此代码时,我收到以下错误:
test.cpp: In function ‘int main()’:
test.cpp:7: error: invalid conversion from ‘bool (*)(const std::string&)’ to ‘void*’
test.cpp:7: error: initializing argument 2 of ‘boost::filesystem3::path::path(const Source&, typename boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename boost::decay<T>::type>, void>::type*) [with Source = char [9]]’
我试图对 Boost 文档做出正面或反面,但我似乎无法弄清楚第二个参数有什么用,或者用什么代替它。任何人都可以对此有所了解吗?
更新:我对要求不是很清楚。至少在过渡期内,我必须同时支持两个版本(1.34.1 和 1.46.1)。是否有一种兼容的方法可以使用相同的代码覆盖两个版本的 Boost,还是我必须求助于#if BOOST_VERSION
魔法?
更新 2:使用#if BOOST_VERSION ...
,因为没有进一步的意见。谢谢您的帮助。