Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
stl vector will grow dynamically by it self automatically

CArray in mfc will not ? as vector has SetAtGrow
Posted
Updated 3-Nov-15 22:01pm
v2

Yes and No.

If you do:
std::vector<int> V;
V[7] = 123;
</int>
it will crash. Well, it will give you nice errors in debug.
But you can do:
V.push_back (1234);

and V will grow appropriately.

That's pretty similar with CArray as well.

I hope that helps,

Iain.
 
Share this answer
 
The very first sentence in the documentation[^]:

Supports arrays that are like C arrays, but can dynamically reduce and grow as necessary.

 
Share this answer
 
Comments
[no name] 4-Nov-15 4:50am    
CArray<cpoint, cpoint=""> 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<cpoint> 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


here in this case SetAtGrow is fixing the value at 5 position
but vector is doing for 3 , 4 ,5 can let me know what s the problem
CPallini 4-Nov-15 5:37am    
There is no problem. It is just a semantic difference between std::vector and CArray.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900