gpt4 book ai didi

c++ - 内存重用中的新旧对象类型

转载 作者:太空宇宙 更新时间:2023-11-04 16:13:15 24 4
gpt4 key购买 nike

If, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, a new object is created at the storage location which the original object occupied, a pointer that pointed to the original object, a reference that referred to the original object, or the name of the original object will automatically refer to the new object and, once the lifetime of the new object has started, can be used to manipulate the new object, if:

— the storage for the new object exactly overlays the storage location which the original object occupied, and

— the new object is of the same type as the original object (ignoring the top-level cv-qualifiers), and

— the type of the original object is not const-qualified, and, if a class type, does not contain any non-static data member whose type is const-qualified or a reference type, and

— the original object was a most derived object (1.8) of type T and the new object is a most derived object of type T (that is, they are not base class subobjects).

不清楚type是什么意思?动态类型还是静态类型?我认为,它是静态类型,否则后一个限制就没有意义。

最佳答案

两者皆有。

只有当静态类型是动态类型的基类时,静态类型和动态类型才能不同,但最后一个项目符号排除了这种情况。

关于c++ - 内存重用中的新旧对象类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25709863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com