dependent scope; need typename in front;

前端 未结 1 1702
遥遥无期
遥遥无期 2020-12-28 13:36

I want to create a template as follows. I want to delete a list of items from vector vec1. And the indexes of the items I want to delete are stored in ind

相关标签:
1条回答
  • 2020-12-28 14:00

    The compiler says

    my_vector.h:21:2: error: need ‘typename’ before ‘std::vector::iterator’ because ‘std::vector’ is a dependent scope

    So you need to write

    typename vector< a_type >::iterator vec1_pre = vec1.begin();
    typename vector< a_type >::iterator vec1_pos = vec1.begin();
    

    See Where and why do I have to put the "template" and "typename" keywords? for the reasons behind it.

    One last remark: In C++11 you can use auto and don't have to think anymore:

    auto vec1_pre = vec1.begin();
    auto vec1_pos = vec1.begin();
    
    0 讨论(0)
提交回复
热议问题