Pilar Rodriguez
Pilar Rodriguez

Reputation: 13

How to create a dynamic array using MFC

I'm learning Visual C++ using MFC and I need to create a dynamic int array without worry about memory location. The array size will be increasing during the run time.

int myArray[5]; // I want to change this as a dynamic array
int counter = 0;
int currentValue;
... more Code

void CScribbleView::OnLButtonUp(UINT, CPoint point) 
{
   myArray[counter] = currentValue;
   counter++;
   currentValue = 0;
... more Code
}

Upvotes: 1

Views: 1837

Answers (1)

Jesus Peralta
Jesus Peralta

Reputation: 671

I think what you are looking for is CArray Class, the changes in your code will be something like:

CArray<int, int> myArray;
int currentValue;
... more Code

void CScribbleView::OnLButtonUp(UINT, CPoint point) 
{
   myArray.Add(currentValue);
   currentValue = 0;

... more Code
}

Upvotes: 3

Related Questions