[英]Unclear compile time error when using std::iterator_traits<>
There's a code that gives an error, which is completely unclear to me. 有一个代码会给出错误,这对我来说是完全不清楚的。 What I want is to pass a pointer to struct/class member through an
iterator_traits
. 我想要的是通过
iterator_traits
将指针传递给struct / class成员。
template<typename Iter, typename S>
S mean(Iter begin, const Iter& end, S std::iterator_traits<Iter>::value_type::* v)
{
//...
}
But even at the declaration of this templated function, MSVS2015 gives following error on the code above: 但是,即使在声明此模板化函数时,MSVS2015在上面的代码上也会出现以下错误:
Error C2653 'value_type': is not a class or namespace name
错误C2653'value_type':不是类或名称空间名称
However, without iterator_trais<...>
ie 但是,如果没有
iterator_trais<...>
即
template<typename Iter, typename S>
S mean(Iter begin, const Iter& end, S Iter::value_type::* v)
{
//...
}
everything compiles properly. 一切都可以正确编译。
Why it cannot recognize value_type
as a class name ? 为什么不能将
value_type
识别为类名?
Compiler bug ? 编译器错误?
It's a simple syntax error. 这是一个简单的语法错误。 You mean:
你的意思是:
template<typename Iter, typename S>
S mean(
Iter begin,
const Iter& end,
typename std::iterator_traits<Iter>::value_type S::* v)
{
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.