02-B-2 QUIZ
(1/1 分数)
Is it possible to replace:
是否可以将视频里向量扩容代码中的:
for (int i = 0; i < _size; i++) _elem[i] = oldElem[i];
in the vector expansion code in the video with:
替代为:
memcpy(_elem, oldElem, _size * sizeof(T));
P.S.This question involves the relevant knowledge of C++
P.S.本题涉及C++的相关知识
是,二者是等价的,不会有任何问题。No, because the range of elemental intervals for the two copies is different.
否,因为二者复制的元素区间范围不同。No, because their efficiency are different.
否,因为二者的效率不同。No, because whether the latter can achieve the purpose is related to element type T.
否,因为后者能否达到目的与元素类型T有关。 No, because whether the latter can achieve the purpose is related to element type T. <br/>否,因为后者能否达到目的与元素类型T有关。 - 正确
EXPLANATION
When T is a non-base type and there is a corresponding assignment operator to perform deep copy, the previous section of code calls the assignment operator, and the latter section can only perform shallow copy.
当T为非基本类型且有对应的赋值运算符以执行深复制时,前一段代码会调用赋值运算符,而后一段只能进行浅复制。