Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Function Implementation Problem...

LiamLiam Member Posts: 1
Hi,

I am working with Visual C++ 6.

I am writing the implementation for a class called List that uses a dynamic array to store numbers. The private variable named data points to the array. I have included code below for a function in the class called attach. This code will take a number from the user(entry in the code example) and will insert it into the list after the cuurent item. The number put into the list with attach becomes the current item in the list. For example if a user input three numbers, it should read like this:
2
4
6

When I do it, the number that I have just entered is garbage(6666.789000e44x). When I put in the next number it becomes garbage and the one that was garbage returns to normal in the list.

Sorry about the confusing explanation, but putting C++ into english is a real art.

Thanks any info; here is the code:




void List::attach(const value_type& entry)
{
size_t i;
if(used==capacity)
resize((capacity*1.1));
else
{
for(i=used; i>(current_index+1); i--)
data[i]=data[i-1];
data[current_index+1]=entry;
current_index++;
}
used++;

}

Sign In or Register to comment.