Problem with for loop in member function

I am trying to get a handle on class templates and I wrote a simple template to create objects able to handle any data type. All the objects do is store data in an array of type T. The class template thus has two private data members; an array of type T, and an int variable m_Used keeping track of the amount of elements currently used in the array.

1
2
3
	private:
		T m_Values[100];
		int m_Used;				


I wrote a public member function Add() to pass an array of data to the object, and a public member function Max() returning the largest value currently stored in the array. Everything works fine if I define Add as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	bool Add(const T values[], int count)
	{
		bool OK = m_Used < (100 - count);	

		if(OK)
		{
			for(int i = 0; i < count; i++)
			{
				m_Values[m_Used++] = values[i];	
			}
		}

		return OK;
	}


For some reason though, the function will not perform the required operation when I define the for-loop in the following way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	bool Add(const T values[], int count)
	{
		bool OK = m_Used < (100 - count);	

		if(OK)
		{
			for(int i = m_Used, j = 0; j < count; i++, j++)
			{
				m_Values[i] = values[j];	
			}
		}

		return OK;
	}


The only change is in the for-loop where I now use two loop counters to do basically the same thing. I am, however, not getting the same results as the second function definition fails to add an array to m_Values. Can anybody tell me what I'm missing?
In the second function the m_Used value stays the same. So if you had 10 objects in the array and you call the second function with 5 objects in the array, m-Used will still be 10. Try adding:
m_Used+=count
inside the second function.
Thank you for your quick reply, you are completely right. I can't believe I did not see this myself. I'll mark the topic as solved.
Topic archived. No new replies allowed.