[英]No matching function for call to 'std::advance' error
I have the following code which Xcode
says it doesn't recognised the signature for std::advance
: 我有以下代码, Xcode
表示无法识别std::advance
的签名:
template<typename Container> const typename Container::value_type&
getNthElement(const Container& container, size_t n) {
auto nElem = advance(container.begin(), n);
return *nElem;
}
The compiler doesn't support C++14
so I can't use cbegin(container)
. 编译器不支持C++14
所以我不能使用cbegin(container)
。 Why is this solution wrong ? 为什么这种解决方案是错误的?
std::advance
doesn't return anything (see here: http://www.cplusplus.com/reference/iterator/advance/ , its return type is void
) so auto nElem = advance(container.begin(), n);
std::advance
不返回任何内容(请参见此处: http : auto nElem = advance(container.begin(), n);
,其返回类型为void
),因此auto nElem = advance(container.begin(), n);
isn't valid. 无效。 As said in comments, you can use next. 如评论中所述,您可以使用next。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.