#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??
}
Pointers to Structs HELP
First things first, I''m new to pointers so don''t be rough!
Here is my code:
The comments tell you my problem
Thanks for your time
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;
SetValues(&thePoint,10.6,20.8);
and use the -> operator in your function
thePoint->x = x;
thePoint->y = y;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement