Pointers to Structs HELP

Started by
1 comment, last by julienX 21 years ago
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
chacha
Advertisement
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;
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
chacha

This topic is closed to new replies.

Advertisement