Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

julienX

Pointers to Structs HELP

This topic is 5750 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

First things first, I''m new to pointers so don''t be rough! Here is my code:
  

#include <iostream>
#include <stdlib.h>
using namespace std;

struct Point
{
   float x,y;
};

void SetValues(Point *,float x,float y);

int main()
{
   Point thePoint;

   SetValues(thePoint,10.6,20.8);

   system("PAUSE");
   return 0;
}

void SetValues(Point *thePoint,float x,float y)
{
   //This is where I am stuck: setting the values if the struct 

   //members. How do I do it??

   eg: thePoint.x = x;

   //I know the above doesn''t work, so how is it done??


}

  
The comments tell you my problem Thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Perhaps what you can do is pass in the address of the struct to the function

SetValues(&thePoint,10.6,20.8);

and use the -> operator in your function

thePoint->x = x;
thePoint->y = y;

Share this post


Link to post
Share on other sites
OMG how could I forget to pass its address?!?!
And how I forget the ''->'' instead of the ''.''?!?!

I guess I''m a little rusty on these areas,
so thanks for reminding me anyway AP!

See ya

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!