Solved

array of pointers to a class

Posted on 2001-06-19
5
186 Views
Last Modified: 2010-04-02
I have a class defined as follows:



class ADNode
{
public:          
     int count;
     int ADNcount;
};
 

What I would like to do is to dynamically create an array of pointers to the ADNode class.  For example, if I knew the size of the class array, I would initialize it as follows.

ADNode *ADN;
ADN = new ADNode[MAX_COUNT];


However, I do not know the value of MAX_COUNT at run time.  I will only know the value at the end of the execution of the program.

My question is, that through a do loop or some type of iteration procedure, how can I incrementally increase the size of the array to the class without loosing information?

I would guess that for the first iteration, I would have:

ADN = new ADNode[0];

and for the second;

ADN = new ADNode[1];

etc...

Please advise on how to solve this problem.

Thanks



0
Comment
Question by:dmontgom
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Shay050799
ID: 6206690
what about linked list ?
0
 

Author Comment

by:dmontgom
ID: 6206701
I do not know how to do linked lists.
0
 
LVL 3

Accepted Solution

by:
Shay050799 earned 100 total points
ID: 6206713
class ADNode
{
public:          
    int count;
    int ADNcount;
    ADNode* next;
}*first, *curr, *Last;
void main(void)
{
first = new ADNode;
first->next = NULL;
curr=first;
while(....)
{
last = new ADNode;
curr->next = last;
curr=last;
}
}
0
 

Author Comment

by:dmontgom
ID: 6206777
Great answer.  Thanks

I am going to work with it and I might have one more comment left later today or tommorow to ask you.  Then I will grade it.

Thanks,

David
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6206931
Shay's answer is spot on, of course, but if you find that your implementation of a linked list needs much more functionality than has so far been described, I would suggest you check out the STL, which has implemented linked lists for you already.

Only a suggestion for the future - I hope it might be of some use.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now