What can and cannot be done safely through void*, and when should a typed alternative be preferred?
Show answer and explanation
An object pointer can be converted to an appropriately cv-qualified void pointer and converted back to the correct object-pointer type, which is useful at C and ABI boundaries. A void pointer cannot be dereferenced, indexed, or used with standard pointer arithmetic; it erases the pointee type and size and carries no lifetime or ownership contract, while cv-qualification must still be preserved (for example, const T* converts to const void*, not void*). Casting it to the wrong type and accessing the result is undefined behavior. Prefer templates, typed callbacks, std::span, std::variant, std::any, or a small type-erased wrapper when the boundary is controlled by C++.
An object pointer can be converted to an appropriately cv-qualified void pointer and converted back to the correct object-pointer type, which is useful at C and ABI boundaries. A void pointer cannot be dereferenced, indexed, or used with standard pointer arithmetic; it erases the pointee type and size and carries no lifetime or ownership contract, while cv-qualification must still be preserved (for example, const T* converts to const void*, not void*). Casting it to the wrong type and accessing the result is undefined behavior. Prefer templates, typed callbacks, std::span, std::variant, std::any, or a small type-erased wrapper when the boundary is controlled by C++.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.