typedef void *pointer

Oct 28, 2008 at 1:20pm
I am not clear about this type?

When we use this type, do we need to allocate memory for it?

Thanks!
Oct 28, 2008 at 5:48pm
Well I'm pretty sure a pointer has a static memory area...the void* just means it can point to any value (char, string, classes, etc).
Oct 28, 2008 at 6:04pm
void* points to any type of data; in order to use it, you must cast it to another valid pointer type (char*, etc.). So I believe it is valid to do something like:

void* ptr = new char;
However you would have to cast it to char* for most operations to make sense out of it. Hopefully someone more skilled can clarify this more for you.

Also, the code you have in the title is just a typedef. With a typedef like that, the following lines would be equivalent:

1
2
void* VoidPtr;
pointer VoidPtr;
Last edited on Oct 28, 2008 at 6:06pm
Topic archived. No new replies allowed.