zoukankan      html  css  js  c++  java
  • c++笔记--关于箭头运算符重载使用

    在stl里面,list的迭代器有重载箭头运算符。之前没搞清楚这个有什么用,看了一些资料,加上自己前面一篇笔记。

    写了下面测试程序:

     1 #include <iostream>
     2 #include <queue>
     3 #include <climits>
     4 #include <algorithm>
     5 #include <memory.h>
     6 #include <stdio.h>
     7 #include <map>
     8 #include <vector>
     9 #include <list>
    10 #include <stack>
    11 using namespace std;
    12 
    13 class test
    14 {
    15 public:
    16     int a;
    17     test():a(2){}
    18 };
    19 
    20 int main(int argc, char *argv[])
    21 {
    22     list<test>::iterator it;
    23     list<test> l;
    24     test t;
    25     l.push_back(t);
    26     it = l.begin();
    27     cout<<it->a<<endl;
    28     return 0;
    29 }

    上面程序中,如果我们声明了list<int>的对象,那么对应的迭代器的箭头操作符其实就没什么作用了。

  • 相关阅读:
    动手动脑5
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每周总结
    2020/10/13
    2020/10/20
  • 原文地址:https://www.cnblogs.com/cane/p/3887467.html
Copyright © 2011-2022 走看看