Once the object is copied to the vector the pointer isn't updated.
If I use a copy constructor to fix this problem I get awkward results.
Could anyone please help me find a solution? Thanks in advance.
#include <iostream>
#include <vector>
using namespace std;
typedef struct {
void *map;
} XE_MAP;
typedef struct MAP_LAYER {
MAP_LAYER()
{
map = (XE_MAP*)malloc(sizeof(XE_MAP));
map->map = (void*)data;
cout << "Data is at " << &data << " and map->map points at " << map->map << endl;
}
unsigned short data[2500];
XE_MAP* map;
};
int main (int argc, char * const argv[]) {
vector<MAP_LAYER> Map;
MAP_LAYER layer;
Map.push_back(layer);
cout << "Data is at " << &Map[0].data << " and map->map points at " << Map[0].map->map << endl;
return 0;
}
Output
Data is at 0xbf5dc008 and map->map points at 0xbf5dc008
Data is at 0x8052568 and map->map points at 0xbf5dc008