工作中发现,Visual Studio 2017 使用c++17编译boost::lexical_cast单独使用是正常的,但如果和boost::property_tree一起使用就会编译出错。复原步骤如下:
一、创建文件:
boost_lexical_cast.cpp
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
#include <boost/property_tree/ptree.hpp>
void main(int argc, char** argv){
std::cout << "boost::lexical_cast<std::string>(123) result is " << boost::lexical_cast<std::string>(123) << std::endl;
}
二、打开VS2017 命令行,执行:cl /EHsc /std:c++17 boost_lexical_cast.cpp
报错如下:
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(453): error C2143: 语法错误: 缺少“,”(在“<”的前面)
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(467): note: 参见对正在编译的 类 模板 实例化 "boost::numeric::convdetail::trivial_converter_impl<Traits>" 的引用
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(453): error C2518: 关键字“typename”在基类列表中非法;被忽略
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(454): error C2518: 关键字“typename”在基类列表中非法;被忽略
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(474): error C2143: 语法错误: 缺少“,”(在“<”的前面)
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(497): note: 参见对正在编译的 类 模板 实例化 "boost::numeric::convdetail::rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder>" 的引用
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(474): error C2518: 关键字“typename”在基类列表中非法;被忽略
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(475): error C2518: 关键字“typename”在基类列表中非法;被忽略
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(504): error C2143: 语法错误: 缺少“,”(在“<”的前面)
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(526): note: 参见对正在编译的 类 模板 实例化 "boost::numeric::convdetail::non_rounding_converter<Traits,RangeChecker,RawConverter>" 的引用
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(504): error C2518: 关键字“typename”在基类列表中非法;被忽略
D:\thridparty\boost_1_65_1\stage\boost/numeric/conversion/detail/converter.hpp(505): error C2518: 关键字“typename”在基类列表中非法;被忽略