【发布时间】:2021-07-15 06:07:16
【问题描述】:
这行注释是什么意思?详情见下方评论:
#include <iostream>
#include <deque>
using namespace std;
void showdq(deque <int> g)
{
deque <int> :: iterator it; /*scope resolution operator means we're getting this obj from this scope, angle bracket is used for template, it seems to be an object, but what does the word iterator doing here?
Deque<int>g is also passed as value, this could be avoided if it was passed as reference right? I'll delete this once i got the answer, thank you!*/
for (it = g.begin(); it != g.end(); ++it)
cout << '\t' << *it;
cout << '\n';
}
【问题讨论】:
-
它声明了双端队列类型的迭代器对象。你可以在google上搜索c++迭代器。
-
iterator是在deque类中定义的类型。 -
cppreference 是阅读此类内容的地方。参见例如en.cppreference.com/w/cpp/iterator 和en.cppreference.com/w/cpp/container/deque。花一些时间在上面。值得您花时间。