It's been a long time since I've sat at the computer as a programmer, so pardon me if this is programming 101.

What I've got is an array of structs, something like this:

Code:

struct Note
{
int nPitch;
int nDuration;
};

Note noteMelody[4][10];

1) I have a function that writes random data to each member of each struct in the array. The question is, how do I pass the struct to this function? Do I just need a refresher course on calling by reference?

2) Can I adjust the size of the array at runtime?

3) Is there a better way to do this than an array of structs? The thing is, each row of the array is one continuous chunk of data (as interpreted) - much like a train. So, I'm going to want to be able to swap, say, position [2][4] with [3][4]. Is this a job for linked lists?

Just the day before yesterday I was talking with someone about Douglas Adams :)

08-22-2006

Daved

1) Just use the same declaration for the parameter as you did for the variable itself: void foo(Note noteMelody[4][10]);

2) Not with that kind of array, at least in standard C++ (gcc has an extension that might allow you to do that). You'd have to use a dynamic array, although I agree with Mario F. that using vector is a much better idea than using a dynamic array.

3) Perhaps, but better could mean a bunch of different things. I would just start with a vector of structs. You can swap elements in a vector or array easily if they are copyable like your struct is.