sam said:
whats the use of void pointers?
Allocation functions return pointers to void. Deallocation functions
take pointers to void. That makes me think that general dynamic
memory mechanisms cannot really avoid using pointers to void.
and when they are useful (on which conditions?)
They are useful when they are necessary. If you can avoid using them,
do.
Please give me example code with some explanation.
In most cases those are left for some C API compatibility where some
functions (like qsort) are written to work with "any object". Same
applies to your own design -- if you don't know what object you're
going to work with at run time, you might want to use pointers to void.
The most common example is a generic callback function. When you are
supposed to give your system a function to call and you want to use
unrelated classes and their member functions for that, a static member
with an extra argument of type void* may be just the solution for you.
V