Inserting numbers into a created class array

closed account (zbREy60M)
I am making a program that will allow me to randomly generate coordinates for the locations of "Gravitars". I havent even implemented the Get or Set functions of the class Gravitar yet, so don't worry about those. I am simply trying to get a 3 dimensional array of random numbers in the for loop at the end of the program, but I am getting problems on the line where I declare "triarray" and on the lines inside the for loop. The error inside the for loop states: "Gravitar" does not define this operator or a conversion to a type acceptable to the predefined operator"

I'm teaching myself C++ so that I can write this program as a project this summer, and any help towards fixing these errors and some pointers would be much appreciated!

Cheers!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Gravitar //creates a class called Gravitar
{
public:
	//public accessors
	double GetRadius();
	void SetRadius(double radius);
	double GetAngle();
	void SetAngle(double angle);
	double GetZed();
	void SetZed(double zed);
private:
	double Radius;
	double Angle;
	double Zed;
};
int main()
{

	


//double normalization = rand() % 32000;
seed();
int m ;
cout << "How many Gravitars?\n\n";
cin >> m;



//intializes the 3 dimensional array as a pointer of type double.
Gravitar* triarray = new Gravitar[m][m][m]; // then use 'new' to allocate an array of m doubles

for (int i = 0; i < m; i++)
{
	
	triarray[i][i][i] = unifRand();//*(normalization);
	cout << triarray[i][i][i] << endl;
}
system("PAUSE");
return 0;
}
Gravitar* triarray = new Gravitar[m][m][m];

you can't use new[] to allocate multidimensional arrays in this way. See http://www.cplusplus.com/forum/articles/7459/
Last edited on
closed account (zbREy60M)
Thanks!
Topic archived. No new replies allowed.