?
Solved

array of pointers to a class

Posted on 2001-06-19
5
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

718 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