Vector temp1 = *ptr->v3; //ptr is a pointer to a polygon
c:\tutorial\gouraud\gp\gp\main.cpp(492) : error C2440: 'initializing' : cannot convert from 'Vector *' to 'Vector'
[\code]
Thanks in advance.
Derefferncing a pointer to a struct
Hello All,
Is derefferncing a pointer to a struct possible? My compiler doesn't seem to think so.
Quote:Original post by DarkMatter2008
Vector temp1 = *ptr->v3; //ptr is a pointer to a polygon
Why are you dereferencing (*) the pointer? Assuming:
struct Poly{ Vector v;};void f(Poly *ptr){ Vector temp1=ptr->v;}
would be fine. ptr->v is like a shortcut to (*ptr).v so no dereferencing is necessary.
You would only need the asterisk if you were dealing with a pointer-to-pointer-to Poly:
void f(Poly **ptr){ Vector temp1=(*ptr)->v; // note parens as per Telastyn's comment above}
This is more like what it is;
I'm trying to dereffernce the struct pointer in order to copy the struct.
struct Vector{//Vector information here}struct Poly{ Vector *v;};void f(Poly *ptr){ Vector temp1=ptr->v; // Needs to be derefferenced so that the Vector can be copied.}
I'm trying to dereffernce the struct pointer in order to copy the struct.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement