[RESOLVED] Void Pointer Function type
Hello,
For a University assignment, I've been tasked to create a memory management Class for a program. We've been given a Class we are to design it from.
I've basically got this all done, but we've been given a virtual function like this in a Class we must inherit:
Code:
virtual void* vcalloc(size_t size) {}
This function should be able to be used as such:
Code:
int *someNewInt = (int*)memObj.vcalloc(sizeof(int));
I don't understand how to do this? Can't use return, and no pointers are passed as a parameter to change. If someone can give me an example of this I would be extremely appreciative! I've Google'd around a bit, but can't find anything that has an example such as this.
Re: Void Pointer Function type
After messing around with it, something like this seems to work:
Code:
void* vcalloc(int size) { return (void *)size; }
But I don't understand how, or if it's correct?
Re: Void Pointer Function type
No unfortunately that is not correct. What you are doing is that you are casting size to a pointer type. That basically means that you are giving the caller a pointer pointing at memory that you do not own and that is very bad.