c++指针存储

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <map>

struct info_keep_level_data_top_stru_t
{
    char data_name[24];
    int data_type; // 1:map; 2:vector; 4:set; 5:queue; 6:
    void **add;
};

struct vector_t {
    int i;
    char *addr;
};

int main(int argc, char *argv[])
{
    struct info_keep_level_data_top_stru_t arr[3];
    char str[24];

    std::vector<struct vector_t> vect, &r_vec = vect, *r_vec1;
    std::map<unsigned int, struct vector_t> m_map, &r_map = m_map;

    //vect.push_back(std::pair<struct vector_t>({10,(char *)&str)});
    vect.push_back({10,(char *)str});

    snprintf(arr[0].data_name, 24, "This ia vector point");
    snprintf(str, 24, "This ia vector_t str");
    printf("\ndata name=%s, %p \n", arr[0].data_name, str);
    arr[0].data_type = 2;
    *arr[0].add = (void*)&vect;

    r_vec1 =(std::vector<struct vector_t> *) *(arr[0].add);
    printf("\n i=%d src vector str:%s addr=%p \n",vect.at(0).i, vect.at(0).addr, vect.at(0).addr);
    printf("\n i=%d vector str:%s \n",r_vec1->at(0).i, r_vec1->at(0).addr);

}

 

运行结果:

data name=This ia vector point, 0x7ffee07e1480

i=10 src vector str:This ia vector_t str addr=0x7ffee07e1480

i=10 vector str:This ia vector_t str

上一篇:map容器实现一对多的映射关系


下一篇:Concurrency-with-Modern-Cpp学习笔记 - 并发架构