Reputation: 1315
I've got a HANDLE
declared like this:
HANDLE handle = new string("test");
How can I get the value from handle
?
Something like this:
string myval = (string)handle; //Cast doesn't work
Upvotes: 0
Views: 6372
Reputation: 234785
If HANDLE
is either a void*
or a string*
then you can use
string myval = *(string*)handle;
or the clearer
string myval = *reinterpret_cast<string*>(handle);
If HANDLE
is any other type then it's likely that the behaviour of your program is undefined.
Note that a value copy of your string will be taken.
Upvotes: 2