Vector and Carray doubt

I have to two classes one is CArray mfc and vector c++

i have to change CArray implementation logic to vector c++

The function i have to changes is SetAtGrow . for that i did one small example as follows:

:
CArray ptArray;
ptArray.Add(CPoint(10, 20)); // Element 0
ptArray.Add(CPoint(30, 40)); // Element 1
// Element 2 deliberately skipped
ptArray.SetAtGrow(5, CPoint(50, 60)); // Element 3



std::vector m_Points1;
m_Points1.emplace_back(CPoint(10,20));
m_Points1.emplace_back(CPoint(20, 30));

m_Points1.resize(5, CPoint(50, 60)); // Element 3



for array in mfc ( as 3,4 elements postion ar empty the values are 0 and 0)
but for vector ( 3,4 is filled with 5th position value)
it should be zero

please let me know the solution how to handle set at grow in vector c++
The CArray::SetAtGrow sets the value at desired index, and grows the array when necessary.

So to mimic the behaviour, I think you could do it like this:

1
2
3
4
m_Points1.push_back(CPoint(10, 20));
m_Points1.push_back(CPoint(20, 30));
m_Points1.resize(6);  // must be 6 so that you could set 5, they will be filled with default CPoint values
m_Points1[5] = CPoint(50, 60);
i can use emplace_bac kinstaed of push_back
dynamicaly its giving problem
Yes, but generally you should write
m_Points1.push_back(CPoint(10, 20));
or
m_Points1.emplace_back(10, 20);
thanks liuyang and fcantroro ..thanks for ur help ...appreciation for that
Topic archived. No new replies allowed.