首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

迭代器和指针有关问题

2012-12-30 
迭代器和指针问题#includeiostream #includelist using namespace std typedef listint IntegerLis

迭代器和指针问题
#include<iostream>
 #include<list>
 using namespace std;
 typedef list<int> IntegerList;
 int main()
 {
    IntegerList intList;
   for(int i=1;i<10;++i)
       intList.push_back(i*2);
   for(IntgerList::const_inerator ci=intList.begin();ci!=intList.end();++ci)
       cout<<*ci<<" ";
   return 0;
 }

IntgerList::const_inerator ci不符合  int* p,这样的声明格式啊,为什么ci前没有* 和数据类型,求大神解释,而且IntgerList::const_inerator又是什么用法,不是只有静态数据才能“类::静态数据”这样的声明方式吗
[解决办法]
因为定义了typedef list<int> IntegerList;
所以IntgerList::const_inerator 等于 list<int>::const_iterator。
const_iterator是属于list类里面的内嵌类,它重载了 operator*(),这个operator*()返回一个指针,当前是返回int*指针,所以他可以像指针那样用。

热点排行