我正在使用一些模板技巧来推断某些函数的返回类型,但是由于某种原因,这段代码无法编译。我希望您的帮助能够理解错误的原因,并在可能的情况下如何解决。
可以找到变体类here。
我有以下代码:
g++ -std=c++11 -Ideps -I. -c -o Value/Value.o Value/Value.cpp
In file included from Value/Value.cpp:1:0:
Value/Value.hpp: In instantiation of ‘Value::ResolveReturnConvertType<To> Value::convertTo() const [with To = int; Value::ResolveReturnConvertType<To> = int; typename ConverterAdaptor<To>::ConverterType = NumericConverter<int>]’:
Value/Value.cpp:27:33: required from here
Value/Value.hpp:88:3: error: no matching function for call to ‘mapbox::util::variant<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, unsigned int, float, bool, std::shared_ptr<const std::vector<std::shared_ptr<const Value>, std::allocator<std::shared_ptr<const Value> > > >, std::shared_ptr<const std::unordered_map<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::shared_ptr<const Value>, std::hash<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::equal_to<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::pair<const std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::shared_ptr<const Value> > > > > >::get() const’
_holder.get<ReturnType>();
^
In file included from Value/Value.hpp:8:0,
from Value/Value.cpp:1:
deps/variant/variant.hpp:680:23: note: candidate: template<class T, typename std::enable_if<(mapbox::util::detail::direct_type<T, std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, unsigned int, float, bool, std::shared_ptr<const std::vector<std::shared_ptr<const Value>, std::allocator<std::shared_ptr<const Value> > > >, std::shared_ptr<const std::unordered_map<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::shared_ptr<const Value>, std::hash<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::equal_to<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::pair<const std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::shared_ptr<const Value> > > > > >::index != mapbox::util::detail::invalid_value), void>::type* <anonymous> > T& mapbox::util::variant<Types>::get() [with T = T; typename std::enable_if<(mapbox::util::detail::direct_type<T, Types ...>::index != mapbox::util::detail::invalid_value)>::type* <anonymous> = <enumerator>; Types = {std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, unsigned int, float, bool, std::shared_ptr<const std::vector<std::shared_ptr<const Value>, std::allocator<std::shared_ptr<const Value> > > >, std::shared_ptr<const std::unordered_map<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::shared_ptr<const Value>, std::hash<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::equal_to<std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::pair<const std::shared_ptr<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::shared_ptr<const Value> > > > >}]
VARIANT_INLINE T& get()
编译器错误
row*column + offset + size*parameter
答案 0 :(得分:0)
这个问题可以关闭,问题是由于我的一个愚蠢的错误,int实际上并不是一个有效的类型,因此模板扣除失败了。