Hi,

I current I have a vector <void*> that I need to populate with values, stored as char*. Is there a way to convert to void*, then back to char* whenever needed?

I have tried casting and using static/reinterpret_cast but when I try to output (converting from void* back to char* that is), I get a null value - unfortunately I can't change the vector to vector<char*> or anything, I have to use it as it is :(

Any help would be much appreciated, thanks :)

#include <iostream>
 
int main()
{
char* p = "eggs on toast";
void* q = (void*) p; // to void*...
char* r = (char*) q; // and back
 
std::cout << r;
return 0;
}

Ah yes, didn't know you could do it that way thanks!

Turned out it was always returning null because nothing was getting put into the vector for some reason, but got it working now thankfully :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.