zoukankan      html  css  js  c++  java
  • C++中 使用数组作为map容器VAlue值的解决方法

    1)是用Vector容器代替数组

    2)使用数组指针(需要注意局部变量的问题,指针是否需要用new创建)

    int red [ 3 ]   = { 1 , 0 , 0 }; 
    int green [ 3 ] = { 0 , 1 , 0 }; 
    int blue [ 3 ]     = { 0 , 0 , 1 }; 
    std :: map < int , int (*)[ 3 ]> colours ; 
    colours . insert ( std :: pair < int , int (*)[ 3 ]>(( GLUT_LEFT_BUTTON ,& red )); 
    colours . insert ( std :: pair < int , int (*)[ 3 ]>(( GLUT_MIDDLE_BUTTON ,& blue )); 
    colours . insert ( std :: pair < int , int (*)[ 3 ]>(( GLUT_RIGHT_BUTTON ,& green )); 
    //Watch out for scope here, you may need to create the arrays on the heap.

    3)使用结构体来构造代替数组的元素,或把数组直接放在结构体内

    struct Triple 

        int color [ 3 ]; 
    }; 

      //Later in code 
    Tripple red = { 1 , 0 , 0 }, green = { 0 , 1 , 0 }, blue = { 0 , 0 , 1 }; 
    std :: map < int , Triple > colours ; 
    colours . insert ( std :: pair < int , Triple >(( GLUT_LEFT_BUTTON , red )); 
    colours . insert ( std :: pair < int , Triple >(( GLUT_MIDDLE_BUTTON , blue )); 
    colours . insert ( std :: pair < int , Triple >(( GLUT_RIGHT_BUTTON , green ));

  • 相关阅读:
    9.vue之v-show
    8.vue之计数器
    Elasticsearch日志-docker安装Elasticsearch
    Elasticsearch日志-错误记录-聚合查询
    Elasticsearch日志-yum安装Kibana
    禅道邮箱配置记录
    docker容器内安装服务
    docker容器内查看容器系统
    CentOS7防火墙配置
    Linux服务器docker运行的时间差
  • 原文地址:https://www.cnblogs.com/fnlingnzb-learner/p/6369233.html
Copyright © 2011-2022 走看看