The program crashes intermittently, when I store pointer value in the string, and convert back to pointer and deference the pointer. Can anyone help me understand the reason for crashing and let me know what could be the issues/defects of storing pointer value in a string.
I have a module, which accepts a callback function pointer ((e.g) void callback(string)) and a string argument. I would like to pass my object pointer to the string argument and when the callback gets called, I can convert the string back to pointer and access the object directly.
I'm not following at all. I mean I get the callback, but "I would like to pass my object pointer to the string argument" doesn't make much sense to me (you can't pass an object as a string unless the object is a string).
Can't you post a simple code snippit to illustrate?
I believe it is because in convertAddressStringToPointer (btw, choose shorter function names XD), you are returning a pointer to a temporary variable which no longer exists when the function is done.
The first hint that your program has a bug should be the need for reinterpret_cast, since you are basically saying that you are smarter than the compiler.
If you are going to be completely type-unsafe, why not just pass a void* to the callback function and then cast it to a pointer to the correct type?