zoukankan      html  css  js  c++  java
  • vector it->和*it

    //每次写代码总是被迭代器的iter->和*iter弄晕,主要是被protobuf弄晕了
    
    #include <vector>
    
    struct test{
        test(){
            memset(this, 0, sizeof(test));
        }
        int a;
        int b;
    };
    
    int main()
    {
        test a, b;
        a.a = a.b = 0;
        b.a = b.b = 1;
    
        //std::vector<test> vecT;
        //vecT.push_back(a);
        //vecT.push_back(b);
        //for (std::vector<test>::iterator it = vecT.begin(); it != vecT.end(); ++it)
        //{
        //    int v_a = it->a;//直接访问元素中的成员
        //    int v_b = it->b;
    
        //    v_a = (*it).a;//(*it)直接就是vector中的保存的元素
        //    v_b = (*it).b;
        //}
    
        std::vector<test*> vecT;
        vecT.push_back(&a);
        vecT.push_back(&b);
        for (std::vector<test*>::iterator it = vecT.begin(); it != vecT.end(); ++it)
        {
            int v_a = (*it)->a;//必须用(*it)获取到指针,然后访问到a
            int v_b = (*it)->b;
        }
        
        return 0;
    }
  • 相关阅读:
    three.js-sun-lensflare
    three.js-Raycaster
    three.js-shadow
    three.js-core
    three.js-Basic-Expand
    Three.js Basic
    md5加密
    密码验证正则表达式
    启动线程开启信的线程
    获取WINDOW.OPEN url js中的get取值
  • 原文地址:https://www.cnblogs.com/zzyoucan/p/5963061.html
Copyright © 2011-2022 走看看