![]() |
1
4
您应该将STL容器类型视为blackbox,它可以根据需要随时复制存储的对象。例如,每次调整容器大小时,都会复制所有对象。
编译器的实现
这个复制发生在STL代码的某个地方,而不是复制构造函数中(因为它使用引用)。
这会在我的机器上产生以下输出:
|
![]() |
2
3
有一个自动生成的=运算符。当您执行v1=v2时,将使用该运算符。在这一点上,“阿尔伯特”的一个例子变成了“伯特”。尝试将此函数添加到foo:
这与自动生成的相同,但会打印出一条调试消息,以便您可以看到正在发生的情况。 |
![]() |
3
1
当使用gcc编译时,“双重复制”不会发生。这必须特定于在VC++中实现std::vector的方式。 |
![]() |
4
1
Visual Studio 2008提供了以下输出: Instance Albert of Foo created! Instance Bert of Foo created! Press any key to continue . . . Instance Albert of Foo copied! Press any key to continue . . . Instance Bert of Foo copied! Press any key to continue . . . Press any key to continue . . . << here auto-generated operator= doing its job Instance Bert of Foo destroyed! Instance Bert of Foo destroyed! << this is Albert was originally Press any key to continue . . .
好像是那样
|
|
Julia · 矢量中相加为总和S的值的数量 2 年前 |
![]() |
C_Rod · 在模板方法中确定STL容器中项目的数据类型 2 年前 |
![]() |
quantumwell · 将空向量放入std::map() 6 年前 |
![]() |
OutOfBound · 对未初始化内存使用算法的优点 6 年前 |
![]() |
DarthRubik · 在使用列表删除之后,迭代器如何不无效 6 年前 |