If nothing else, you seem to be a dereference away from having an integer.
Soma
If nothing else, you seem to be a dereference away from having an integer.
Soma
This is already the second thread about the same problem
see compare void pointer
You have never shown any code. If you really want a correct answer then it is time that you post a complete example.
Kurt
That's all I do,nowhere else in the code I need this void*.Just to check in the function getRecords if it's a char* or int and cout things.Code:void* pVoid; int val=7; pVoid = &val; getRecords("num",pVoid);//first call of function getRecords(NULL,"John");//second call of function getRecords(char* field,const void *value){ if(strncmp(field,"num",3)==0) { //this means value is int if(reinterpret_cast<int>(value)==24){ cout<<"There was a match!"<<endl; counter++; } } else{//this means value is char* if(strncmp(value,"John",10)==0) { cout<<"There was a match of type2!"<<endl; }}
Is the casting from const void* to int correct?
It returns large negative values
Ok that might get us somewhere
KurtCode:void* pVoid; int val=7; pVoid = &val; getRecords("num",pVoid);//first call of function getRecords(NULL,"John");//second call of function getRecords(char* field,const void *value){ if(strncmp(field,"num",3)==0) { //this means value is int // here you should check for NULL otherwise strncmp() will segfault if(reinterpret_cast<int>(value)==24){ // you are passing an int * that is cast to a void * // should be // if( * static_cast<const int*>(value)==24){ cout<<"There was a match!"<<endl; counter++; } } else{//this means value is char* if(strncmp(value,"John",10)==0) { // a cast from const void * to const char * is not implicit // you need // if(strncmp(static_cast<const char *>(value),"John",10)==0) { cout<<"There was a match of type2!"<<endl; }}
Last edited by ZuK; 05-13-2012 at 06:32 AM.