Declaring an array of records in MC++
How do you declare an array of records in MC++? And have a ptr point to it? Thanks.
DotNetUser
Junior Poster in Training
69 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
struct Record
{
string title;
int playtime;
Record *next;
};
Record **ListOfRecords = new Record*[42];
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118
How about declaring an array of records without using pointers?
I get an error when I declare it this way:
Record ListOfRecords[];
I want to have an array of 100 records. Then have a pointer point to the array. This way I can pass the address to a function for processing.
DotNetUser
Junior Poster in Training
69 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
If MC is a C or C++ compiler, you have to put a number inside those brackets to tell it how big that array is going to bel
Record ListOfRecords[100];
You don't need another pointer in order to pass it to another function.
// use only ONE of the following, not all three. It shows three ways
// to code the function.
void foo(Record ListOfRecords[100])
void foo(Record ListOfRecords[]) << this is also ok
void foo(Record* ListOfRecords) << so is this
{
// blabla
}
int main()
{
Record ListOfRecords[100];
// pass the array to function foo()
foo(ListOfRecords); <<< see here
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343