Simply read the documentation on
CArray::SetAtGrow
and do exactly what it does for a vector.
- Get the current size of the vector: http://www.cplusplus.com/reference/vector/vector/size/[^].
- Compare the size with the required index. If index is more than
size − 1
, find out how many elements you need to add to place the element at the index
. - If the number of elements to add is greater then zero, add appropriate number of missing elements: http://www.cplusplus.com/reference/vector/vector/push_back[^].
It make require you to add more elements than one. One element (at the index of newSize − 1
) is your function argument. What are the additional elements, is up to you. The documentation of SetAtGrow
does not clearly specify it. You may or may not experiment with it, but it's way more important to do what you really want. - If you don't need to add more elements, you have to replace some existing element at
index
with new element. Do it: http://www.cplusplus.com/reference/vector/vector/assign[^].
Please see:
http://www.cplusplus.com/reference/vector/vector[
^].
Now, one little note: first of all, think about reviewing your code. Chances are, the code using
CArray::SetAtGrow
is not well designed. The functionality of this function is questionable and looks like too much of
ad-hoc developers of MFC used for their internal purposes. I would never use it. Just some food for thought.
Good luck.
—SA