tungsim
asked on
new operator .
I use VC++ 5.0
I define a class like that
class FACT
{ char * content}
after that I init an array
arr=new FACT[3];
but it allocate 4 elements each 32 bits.
the first elements contain number of elements in the array(3),and then "Debug assertion failed" because of arr point to the second elements so it can't free the mem .
How can I allocate only 3 elements by new operator.
Thanks.
I define a class like that
class FACT
{ char * content}
after that I init an array
arr=new FACT[3];
but it allocate 4 elements each 32 bits.
the first elements contain number of elements in the array(3),and then "Debug assertion failed" because of arr point to the second elements so it can't free the mem .
How can I allocate only 3 elements by new operator.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks nietod .
Now where do you get this error? is it when you delete? do you delete using "delete" or using delete []"? If you allocate with new []" you must delete with "delete []" Like
arr=new FACT[3];
delete [] arr;
not
delete arr; // this is an error.
Let me know if you have any questions.