Question about vector iterator in template functions

后端 未结 5 1780
慢半拍i
慢半拍i 2020-12-24 07:54

I\'m trying to learn the STL library and I\'m having a weird problem. This code compiles perfectly:

void Show(vector myvec)
{
    vector

        
5条回答
  •  渐次进展
    2020-12-24 08:26

    You need to say typename vector::iterator it.

    On another note, you're passing vectors by value. That means the entire vector gets copied in the function call. void Show(vector const &myvec) and using const_iterator would be wiser.

提交回复
热议问题