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;

24th May 2020, 8:06 PM
Mustafa K.
Mustafa K. - avatar
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.
24th May 2020, 8:27 PM
Dennis
Dennis - avatar