数据结构学习笔记:错题1(未)

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++的相关知识

Yes, they are equivalent and there will be no problem. 
是,二者是等价的,不会有任何问题。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为非基本类型且有对应的赋值运算符以执行深复制时,前一段代码会调用赋值运算符,而后一段只能进行浅复制。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值