[MS VS 2013]C++ fail on delete operator "Debug Assertion Failed!" -


i getting error when try complie (trivial, attached below) code:

debug assertion failed!

program: ......\project1.exe

file: f:\dd\vctools\crt\crtw32\misc\dbgdel.cpp

line: 52

expression: _block_type_is_valid(phead->nblockuse)

so, here code:

class t1 { private:     int* foo; public:     t1()     {         foo = new int[4];         foo[0] = 1;         foo[1] = 2;         foo[2] = 3;         foo[3] = 4;     }     ~t1()     {         delete[] foo;     } };  int main() {     t1 t1;     t1.~t1(); } 

while kinda ugly , incomplete, unquestionably correct. wrote 1 after experiencing exact same error code performing more sophisticated memory management, see going on. still no clue whats wrong, though.

no compiler errors/warnings, no linker errors/warnings. error occurs when execution reaches delete[] foo; line.

as if not insane enough, program executes fine when switch solution configuration debug release - execution reaches end of main function no errors. clues how fix this?

you doing double delete. first calling ~t1(), when main() goes out of scope. first jens noted, there never reason call destructor directly.

the error occurs in debug mode because object checked see if has been deleted when in debug. if put breakpoint on line giving error see first time delete called ok , error occurs on second delete automatically called when object goes out of scope.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -