Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot delete a CObArray object!!

Status
Not open for further replies.

VincentP

Programmer
Apr 1, 2001
116
Hi,

I am trying to have a CObArray of CObArray pointers to have a 2-dimensional array of CObjects. When I want to delete the 2nd CObArray's stored into the first one, I get an "Assertion Failed" error. To make sure I was not doing something wrong, I tried the following:

Code:
CObArray * tmp = new CObArray; 
delete tmp; 
[\code]

and it does NOT work!!! 

IMHO, this SHOULD work. Am I wrong? 

Anybody has an idea to work around this problem??? Is it a known problem?? 

I have just installed SP5 (VC++ 6.0) (I don't know which one I had before, if any, but that did not change that problem...) 

Vincent
 
Hi Vincent,

Do you get a compile time error at this statement,
CObArray * tmp = new CObArray;
Well I get this error at both the statements.
And can u please tell me why are u doing a new to allocate memory for a CObArray Object.
Awaiting your reply.

Thanx and Regards
Sun
 
Well, I have sort of worked around my problem for now... It *looks* like when I just "Ignore" the "assertion failed" warning, my object gets deleted properly (no GPF message, no memory leaks detected by the debugger...)

I found out that my problem is intimatelly related to WHERE in my program I do that. The error only occurs for most sorts of objects (including CObArray's), and only when executed inside a special DLL I am working on. I am not done investigating my problem, but now I know it's not specific to CObArray's, at least.

To answer your questions: no, I don't have compile errors, only run-time assertion errors (in Debug mode).

I want to have to use

Code:
new CObArray
[\code]

in the following context:

[code]
CObArray oaMyArray;
oaMyArray.SetSize(10);
for(int i = 0; i < 10; i++)
{
    oaMyArray[i] = new CObArray;
    ((CObArray*)oaMyArray[i])->SetSize(5);
}
...
[\code]

So that way I have a 2D array of objects. Anyways, I think I have found a way to have real 2D arrays.

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top