When I try to compile the following code…
struct MemPages
{
size_t size;
volatile sig_atomic_t acc;
};
typedef std::map<unsigned long, MemPages> PagesMap;
PagesMap pagesMap;
............
pagesMap.insert(pair<unsigned long, MemPages>((unsigned long)addr, memPages ));
............
// This is Line 531
MemPages& mp = pagesMap[addr]; // Error here
I get the following error…
**replication.cpp:531: error: invalid conversion from ‘void*’ to ‘long unsigned int’
replication.cpp:531: error: initializing argument 1 of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = long unsigned int, _Tp = MemPages, _Compare = std::less<long unsigned int>, _Alloc = std::allocator<std::pair<const long unsigned int, MemPages> >]’
make: *** [all] Error 1**
Any Idea, what is going on?
The error says:
addris apparently avoid*; the key type of your map is aunsigned long. You need to pass anunsigned long(or, at least something that is convertible to an integer) tooperator[].The casting of a pointer to an integer (
(unsigned long)addr) in your code is odd: there really shouldn’t be any reason to do this. If the key type of thestd::mapshould be a pointer type, then you should make it a pointer type…