0
Is it possible to cast a void pointer to the type of its content?
I mean something like this, bool b; void* ptr = &b; cout<< *( type(b)* )ptr;
1 ответ
+ 2
Well yea
bool b = true;
void* p = &b;
std::cout << *(decltype(b)*)p;
But this only applies if b is in scope and you know where p is pointing to.
Most of the time you'll want to avoid void* unless you know what you're doing.