谜语答案

谜语答案1. Invoking heap(20) in heap(int *a,int size), at line 2,
an instance of heap is created
(which can be a local variant to be referenced) without being named as
an variant.
Let's call it heap_drop.2. root[i] in heap(int *a,int size), at line 5, is a member of the instance that
will be created by heap(int *a,int size), just this constructor
itself.
root[i] in heap(int *a,int size) is NOT a member of heap_drop mentioned above,
therefore it has not been allocated memory yet.
1 heap(int *a,int size){
2 heap(20);
3 cout<<"hhh";
4 for(int i = 0;i<size;i++){
5 root[i] = a[i];
6 }
7 heapSize = size;
8 build_Heap();
9 }
10 heap(int maxSize){
11 root = new int [maxSize];
12 }典典一句话评论:
heap(20) 不是调用构造函数初始化当前对象,而是分配了一个临时对象然后立刻销毁。感谢某用功同学提供代码示例。

One thought on “谜语答案”

Leave a Reply

Your email address will not be published. Required fields are marked *