You answer may not satisfy the time cost requirements for the operations on vectors. [#2879751@0 -ROLIA.NET 相约加拿大网上社区 之 枫下论坛 & 枫下部落, 枫下论坛主坛 ]
You answer may not satisfy the time cost requirements for the operations on vectors.
by
benbenli
(大岭)
at
2006.4.2 10:10
(#2879751@0)
There are time cost requirements for the operations on vectors. For example, an insert should cost almost O(n) where n is the number of elements in the vector. In your answer, if the sizeof(T) is very big, the time cost is too big. To solve this issue, the objects of T are not directly stored in the array, but the address of the objects. So when you move objects, you only move the the pointers whose size is 4 in 32-bit machine. Thus the time cost can fulfill the requirements.