Pointer to void in C++?

tunnuz picture tunnuz · Jan 4, 2009 · Viewed 8k times · Source

I'm reading some code in the Ogre3D implementation and I can't understand what a void * type variable means. What does a pointer to void mean in C++?

Answer

Johannes Schaub - litb picture Johannes Schaub - litb · Jan 4, 2009

A pointer to void, void* can point to any object:

int a = 5;
void *p = &a;

double b = 3.14;
p = &b;

You can't dereference, increment or decrement that pointer, because you don't know what type you point to. The idea is that void* can be used for functions like memcpy that just copy memory blocks around, and don't care about the type that they copy.