I'm doing a class in c++ that supports any kind of variable to help me in a future project. The thing is, when I try to assign a value to a void*
variable, I get the error: void*
is not a pointer-to-object type. Here is the code:
int main (void) {
void* a;
int x;
a = malloc(sizeof(int));
x = 120;
((int)(*a)) = x;
printf("%d",((int)*a));
free(a);
system("pause");
return 0;
}
I see it like I am trying to assign the value of x in the memory block reserved for a. I want that the value stored in x be stored in the memory block of a. Can any1 help me?