-
1D array of class help
Code:
#include <iostream.h>
#include <stdlib.h>
#include <dice.h>
class Point{
public:
int x, y;
};
int main()
{
Point[] path = new Point[2];
path[0].x = 1;
path[0].y = 1;
path[1].x = 3;
path[1].y = 3;
cout << path[0].x << " " << path[0].y << endl;
system("PAUSE");
return 0;
}
The above gives me a "parse error before [". How would I create a 1D class array for the Point class?
-
You are trying to allocate memory for a non-pointer type. You need to do one of the following:
Code:
Point *path = new Point[2];
// blah
delete [] path;
Or...
Code:
Point path[2];
//blah..
-
just think of it like a normal data type...
and then replace with your data type