我需要将 multimap 转换为 void 缓冲区,并将其传递给应该重建 multimap 的函数。
我知道有一种简单的方法可以简单地传递多图,但我需要通过 void 指针来做,所以请看下面我的逻辑:
using namespace std;
void reconstruct_mm(void *ptr, size_t len) {
multimap<int, int> *mm = ptr;
mm = (multimap<<int, int>*>malloc(len));
*** print the following 10, 20, 30...
}
int main (void) {
void *buffer;
size_t buffer_len = 0;
multimap <int, int> m;
// fill in multimap with values
m.insert(pair <int, int> (1, 10);
m.insert(pair <int, int> (2, 20);
m.insert(pair <int, int> (3, 30);
// from this point I need your help, I only wrote logic what I expect from the program.
buffer = &mm;
buffer_len = sizeof(mm);
reconstruct_mm(buffer, buffer_len);
}
先感谢您!