'How can I store a uint32_t or uint64_t in a void pointer
I have a uint32_t (and in the future it might become uint64_t) variable. There is a function in one of the libraries that I use that allows passing a void pointer to it. How can I pass a uint32_t to this void pointer:
uint32_t myEntity = 1242242;
// not a pointer; so, error about invalid conversion
actor->userData = static_cast<void *>(myEntity);
I can't use a pointer to this primitive type because the value can be coming from an argument or similar and since it is a uint, I don't want to use references for it.
Is there some way that I can set this value into a void pointer; so that, I can then retrieve it the same way without creating a value in the heap for it to work properly. Otherwise, I will need to manage the destruction of the objects in order to not cause memory leaks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
