简体   繁体   English

使用std :: iterator_traits <>时出现不清楚的编译时错误

[英]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.

相关问题 遇到错误:“struct std::iterator_traits”中没有名为“iterator_category”的类型<std::vector<int> &gt; - Encountring error: no type named ‘iterator_category’ in ‘struct std::iterator_traits<std::vector<int> > 专门化iterator_traits - specializing iterator_traits “std :: iterator_traits的显式特化 <char *> 实例化后“(CLang) - “Explicit specialization of std::iterator_traits<char *> after instantiation” (CLang) “struct std::iterator_traits”中没有名为“value_type”的类型 - no type named ‘value_type’ in ‘struct std::iterator_traits libddc ++和libc ++之间的std :: iterator_traits差异 - std::iterator_traits divergence between libstdc++ and libc++ 在struct std :: iterator_traits &lt;...&gt;中没有名为“ pointer”的类型 - no type named ‘pointer’ in struct std::iterator_traits<…> std::iterator_traits 中类型别名的“默认值”总是正确的吗? - Are the “defaults” for the type alises in std::iterator_traits always correct? iterator_traits SFINAE友好 - iterator_traits SFINAE friendliness std::iterator_traits 中的 iterator_category 与 iterator_category() 有什么区别 - What is a difference between iterator_category vs iterator_category() in std::iterator_traits 铛错误:c ++ / 4.8 / bits / stl_iterator_base_types.h:227:29:错误:&#39;std :: iterator_traits中没有名为&#39;iterator_category&#39;的类型 <unsigned long> “ - clang error: c++/4.8/bits/stl_iterator_base_types.h:227:29: error: no type named 'iterator_category' in 'std::iterator_traits<unsigned long>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM