Jump to content
  • Advertisement
Sign in to follow this  
DarkMatter2008

Derefferncing a pointer to a struct

This topic is 3413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello All, Is derefferncing a pointer to a struct possible? My compiler doesn't seem to think so. 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.

Share this post


Link to post
Share on other sites
Advertisement
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
}

Share this post


Link to post
Share on other sites
This is more like what it is;


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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
(*(ptr->v)); (iirc)


hmmm, thouse extra set of brackets seem to have done the trick.

I tried this before

*(ptr->v)

with out the outer ones but it didn't work.

anyways, thank you very much Telastyn :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!