迭代器(iterator)并非指针

来源:互联网 发布:java反序列化利用工具 编辑:程序博客网 时间:2024/06/05 19:01
如下代码产生如下错误:
test.cpp: In function `int main()':
test.cpp:15: error: cannot convert `__gnu_cxx::__normal_iterator<label**, std::vector<label*, std::allocator<label*> > >' to `label**' in initialization

#include<iostream>
#include
<vector>
using namespace std;

struct label
{
    
int x;
    
int y;
}
;

int main()
{
    vector
<label*> plabel;
    label 
** pCurrlabel = plabel.begin();
    
return 0;
}

 
改为
label * pCurrlabel = *(plabel.begin());
就好了。

因为plabel.begin()返回的是一个迭代器,并不能自然地转化为指针。

(摘自:www.linuxquestions.org)


原创粉丝点击