MyClass obj; void *p; p = (void*)&obj; // Explicit cast. // or: p = &obj; // Implicit cast, as every pointer is compatible with void *
But be careful! obj is allocated on the stack so that as soon as you leave the function, the pointer becomes invalid.
Edit : Updated to show that explicit casting is not required in this case, since each pointer is compatible with the void pointer.
source share