Array of a Class Type containing an array -- array sizes not know at compile time.
I have the following types declared.
Code :
class Piece
{
public byte type;
public byte loc;
}
class Config
{
public Config( int n ) { piece = new Piece[ n ]; }
private Piece [] piece;
private int next;
private int parent;
}
class QHT
{
private Config [] conf;
public QHT( int m, int n );
}
In the constructor for QHT, I want to allocate "conf" to an array of m "Config"s where each Config contains an array of n "Piece"s. The values of m and n are not known at compile time. (If necessary, I could fix the value of m at compile time but
I can't do this for n. Also, m will be rather large.)
How can I do this in Java?
Re: Array of a Class Type containing an array -- array sizes not know at compile time.
Quote:
Originally Posted by
GCRhoads
...In the constructor for QHT, I want to allocate "conf" to an array of m "Config"s where each Config contains an array of n "Piece"s...
Two steps in the constructor for QHT:
- Set conf equal to a new array of m Configs.
- Make a loop that sets each element of conf equal to a new Config(n).
Quote:
Originally Posted by
GCRhoads
...Also, m will be rather large....
So???
Cheers!
Z
Re: Array of a Class Type containing an array -- array sizes not know at compile time.
Quote:
Originally Posted by
Zaphod_b
Two steps in the constructor for QHT:
- Set conf equal to a new array of m Configs.
- Make a loop that sets each element of conf equal to a new Config(n).
Z
Thanks!