Note that I’m 95% unfamiliar with pointers.
So here’s my dilemma, I have a structure let’s call it foo
struct foo{
int a;
}
so let’s create an instance of foo
foo test;
Now I want to assign a void pointer to point to this
void *ptest;
ptest = &test;
This all works great, but when it comes to modifying the contents (ie int a within foo), I’m not sure how to approach this. I tried static_cast like this:
static_cast<foo*>(ptest).a=0;
but that didn’t work either. Any help would be appreciated. Thanks
You’re casting it to a pointer, thus you need to dereference it using the
*operator or use the->operator.Option A:
Option B: