I met a small problem when I was doing a 2-question today:
The code I modified was as follows:
1 //Proj1.cpp2#include <iostream>3 using namespacestd;4 5 classMyClass {6 Public:7MyClass (intlen)8 { 9Array =New int[Len];TenArraySize =Len; One for(inti =0; i < arraySize; i++) AArray[i] = i+1; - } - the~MyClass () - { - //ERROR **********found********** - Delete array; + } - + voidPrint ()Const A { at for(inti =0; i < arraySize; i++) - //ERROR **********found********** -cout << Array[i] <<' '; - -cout <<Endl; - } in Private: - int*Array; to intarraySize; + }; - intMain () the { * //ERROR **********found********** $MyClass obj (Ten);Panax Notoginseng - obj. Print (); the return 0; +}
No problem after running successfully, but the 18th line gave me the wrong.
I've always thought that array[] and array are not the same, but I've looked at the relevant information:
- Array represents this number, which is the equivalent of a pointer to the first element (&a[0]), that is, to the first address of the array, the other elements of the array can be obtained by the displacement of the arrays, at this time the advance is in the array of individual element type units
- Array[] Represents the address of the variable instead of the array[], but instead takes the address of the array element. Although array[] and array have the same memory address, but they do not have the same meaning, it represents the entire array, its advanced unit is the entire array of bytes length
And about delete and delete[] My understanding also has a misunderstanding:
http://blog.csdn.net/shandaliuyan/article/details/5930719
The final use principle is: New and delete, new[] and delete[] corresponding to use, array selection using delete[].
C + + array deallocation problem