Solved

array of pointers to a class

Posted on 2001-06-19
5
190 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 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