我有这个c ++代码片段在visual studio中工作正常但在gcc中出错。欢迎任何有关如何使其工作的建议?
template <typename ConvertType>
inline bool Parse(const std::string& input, ConvertType& output)
{
std::stringstream stream(input);
stream.imbue(std::locale::classic());
return (stream >> output) != NULL;
}
我收到此错误:
./Configuration/Option.h:32:38: error: cannot bind 'std::basic_istream' lvalue to 'std::basic_istream&&' /usr/include/c++/4.6/istream:852:5: error: initializing argument 1 of 'std::basic_istream& std::operator>>(std::basic_istream&&, _Tp&) [with _CharT = char, _Traits = std::char_traits, _Tp = Color]'
答案 0 :(得分:2)
(stream >> output)
返回对流的引用,无法与NULL
进行比较。你可以简单地返回
return (stream >> output);
将通过调用operator void*() const
(C ++ 11中的explicit operator bool() const
)来测试流,该fail()
调用{{1}}函数来测试操作是否成功。