Hello everyone;
I've been struggling with trying to figure out how to get this struct program to work and I'm at a total loss on this. Basically I need to create two structs POINT which will have an X and Y values, and a LINE struct which will include 2 POINT structures as its data members. The program also has a function called getData and takes input from the user, and another function called printData which will be the endpoints of a line. However, when trying to test to see if I even have my code correct, I keep getting "error C2597: illegal reference to non-static member 'Point::m_Xcoord'", and I'm not sure where to go to get past this. I've been working on this for several days now, and can't seem to get past this error. The code I'm using is as follows:
#include "stdafx.h"
using namespace std;
//Create structs POINT and LINE
struct Point
{
float m_Xcoord;
float m_Ycoord;
}; // closing brace for struct
struct Line
{
Point m_Left;
Point m_Right;
static void getData();
static void printData();
}; // closing brace for struct
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Welcome to the Struct Program" << endl;
Line aLine;
aLine.getData();
aLine.printData();
return 0;
}
//Functions
void getData(Line aLine)
{
//int x,y;
cout << "/nYou will need to enter in 2 for this program." << endl;
cout << "/nPlease enter in your 2 coordinates: ";
cin >> Point::m_Xcoord >> Point::m_Ycoord;
//cout << "/n/nPlease enter in your 2 Y coordinates: ";
//cin >> c >> d;
} //closing bracket for function
void printData(Line aLine)
{
cout << "/nYour line starts with: " << aLine.m_Left << " and ends with: " << aLine.m_Right << endl;
cout << "/nThank you for trying this program." << endl;
cout << "/nPress any key to continue.......";
} // closing brace for function
`
I'm hoping that I'm close to the ballpark area here, but have a feeling I'm not too clear on structs.... Any help would be very appreciated with this one.
Thanks,
dax