What are void pointers for in C++?

c++, pointers

Solution

Basically, a remnant from C.

What is their use?

In C, they were and are used widely, but in C++ I think they are very rarely, if ever, needed, since we have polymorphism, templates etc. which provide a much cleaner and safer way to solve the same problems where in C one would use void pointers.

Can I make them point to a variable of any type?

Yes. However, as others have pointed out, you can't use a void pointer directly - you have to cast it into a pointer to a concrete data type first.

Problem

My question is simple: What are void pointers for in C++? (Those things you declare with `void* myptr;`) What is their use? Can I make them point to a variable of any type?

Original source