std::map::const_iterator template compilation error

前端 未结 3 1124
灰色年华
灰色年华 2020-12-20 00:56

I have a template class that contains a std::map that stores pointers to T which refuses to compile:

template 
class Foo
{
public         


        
3条回答
  •  遥遥无期
    2020-12-20 01:34

    You need:

    typename std::map::const_iterator begin() const { return items.begin(); }
    

    Or simpler

    typedef typename std::map::const_iterator const_iterator;
    const_iterator begin() const { return items.begin(); }
    

    This is because const_iterator is dependent name on T so you need to tell compiler that it is actually type.

提交回复
热议问题