944,111 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3954
  • C++ RSS
Mar 14th, 2006
0

Declaring an array of records in MC++

Expand Post »
How do you declare an array of records in MC++? And have a ptr point to it? Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
DotNetUser is offline Offline
69 posts
since Jun 2005
Mar 14th, 2006
0

Re: Declaring an array of records in MC++

C++ Syntax (Toggle Plain Text)
  1. struct Record
  2. {
  3. string title;
  4. int playtime;
  5. Record *next;
  6. };
  7.  
  8. Record **ListOfRecords = new Record*[42];
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Mar 24th, 2006
0

Re: Declaring an array of records in MC++

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
DotNetUser is offline Offline
69 posts
since Jun 2005
Mar 24th, 2006
0

Re: Declaring an array of records in MC++

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
}
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Counting Spaces in a string
Next Thread in C++ Forum Timeline: Dev C++ Help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC