大该是, 我c ++ map, 如果在 pack 来改变字节对齐的方式, 就会乱.
// map_class.h
#pragma once
#pragma pack(1)
#include <map>
#include <string>
typedef std::map<uint32_t, std::string>::iterator it_image_t;
typedef std::map<uint32_t, std::string>::value_type vt_image_t;
class upimg_i1{
public:
std::map<uint32_t, std::string> *up_images;
upimg_i1(){
up_images = new std::map<uint32_t, std::string>();
}
int test_map();
~upimg_i1(){}
};
// map_class.cpp
#include "map_class.h"
int upimg_i1::test_map(){
printf("up_images: %ld\n", up_images->size());
up_images->insert(vt_image_t(1, std::string("sdfjsfjlds")));
printf("up_images after insert: %ld\n", up_images->size());
}
int main(){
auto d = new upimg_i1();
d->test_map();
return 0;
}
能够编译, 但是运行出错:
up_images: 0
up_images after insert: 22084
这个非常离谱, 有经验的大佬帮忙看看!!