由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - [合集] 请教一个c++ 中 delete [] 的问题
相关主题
C++ virtual function 定义在 derived class 会怎么样?new了指针,delete的时候出错了
An interesting C++ compile error问个C++中重复删除指针的问题
C++ private inheritance. v.s. compositionone question about overloading operator delete
C++ Q98: Call member function in virtual function (转载)What is wrong?
c++ dynamic castdelete sheets from Excel workbook in C# (转载)
请教 C++的一个困惑 (operator delete)C++疑问
问个object suicide问题interview question: make all class member functions virtual (转载)
linux 能查到 deleted file list 吗Help! Virtual Destructor
相关话题的讨论汇总
话题: delete话题: base话题: delet话题: derived话题: complier
进入Programming版参与讨论
1 (共1页)
b***y
发帖数: 2799
1
☆─────────────────────────────────────☆
julietzn (juliet) 于 (Thu Feb 21 22:51:54 2008) 提到:
面试的时候被问到的
int * p = new int[10];
delete [] p;
complier 如何实现 delete [], 他们怎么知道有10个int 需要 delete.
接下来是一个衍生出来的问题:
class Base{};
class Derived : public Base{};
Base *p;
Derived q;
p = &q;
如果delet p, 实际上应该delet p所指向的 object q.
那么这个delet 需要两步实现:
1. call the destruction function of q // There is no problem, if the
destruction of q is virtual.
2. free the memory of q. //question: complier 是如何知道要release 多少memo
1 (共1页)
进入Programming版参与讨论
相关主题
Help! Virtual Destructorc++ dynamic cast
C++ 弱问一个请教 C++的一个困惑 (operator delete)
C++小插曲问个object suicide问题
virtual function questionlinux 能查到 deleted file list 吗
C++ virtual function 定义在 derived class 会怎么样?new了指针,delete的时候出错了
An interesting C++ compile error问个C++中重复删除指针的问题
C++ private inheritance. v.s. compositionone question about overloading operator delete
C++ Q98: Call member function in virtual function (转载)What is wrong?
相关话题的讨论汇总
话题: delete话题: base话题: delet话题: derived话题: complier