Solved

array of pointers to a class

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connecting to MS SQL db from Win32 application written in C 3 79
Move constructor only called if marked noexcept? 6 98
Find Visual Studio Tools 2 92
C++ question 3 62
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

22 Experts available now in Live!

Get 1:1 Help Now