As title says, I’m currently doing some small hacks with pointers in C++, but something isn’t working out here’s what I got:
uintptr_t texture_pointer = (int)((void*) &texture);
Where texture is a class; this seems to work fine, as I’m getting a pointer value out, and I have insured that I’m getting the same value into my other function, which is supposed to get the object back; this is the code that fails:
std::cout << "C++ BEFORE: " << texture_pointer << std::endl;
Texture texture = *(Texture*)((void*) texture_pointer);
std::cout << "C++ AFTER: " << (uintptr_t)((void*) &texture) << std::endl;
The output I was excepting; was that the same number for both, however I’m getting two different numbers, hence why I think there must be an error, but I can’t seem to find it.
Example output:
C++ BEFORE: 2685236
C++ AFTER: 2684960
This line:
creates a new
Textureobject as a copy of the original one. Obviously, this has a different address to the old one.You could do this:
(i.e. create a reference to the old one).
But in general, messing about with pointers like this is more trouble than it’s worth.