I made a map, I need that map in another thread, so I made a pointer that points to my map and send it to the other thread. But when I want to look if the value in a map is not NULL (Pointer) I get an error.
This is a example codee:
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
int test = 1;
map<int,void *> handle;
map<int,void *> * handle2;
handle[0] = &test;
handle2 = &handle;
if(*handle2[0])
{
cout << "Works\n";
}
system("Pause");
return false;
}
This is the error I get:
error C2451: conditional expression of type ‘std::map<_Kty,_Ty>’ is illegal
How can I cheak for a 0 pointer in this case?
handle2is a pointer to a map, sohandle2[0](equivalent to*handle2) is the map itself. As the error says, this can’t be used as a conditional expression.If you want to check whether
handle2is null, just sayhandle2; for the element of the map with key 0, you want(*handle2)[0].