I am getting run-error on providing default destructor. However, if left to compiler to provide default destructor it is running safely.
class foo
{
private:
int m_size;
int* m_array;
public:
foo( int a_size ):m_size( a_size ), m_array( new int(a_size) ){}
~foo() {
delete [] m_array;
}
void setArray();
};
void foo::setArray()
{
for( int i=0; i<m_size; ++i )
m_array[i] = 10*i;
}
int main( int argc, const char* argv[] )
{
class foo obj( 6 );
obj.setArray();
system( "pause" );
return 0;
}
Runtime Error:
This may be due to a corruption of the heap, which indicates a bug in Destructors.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Templates.exe has focus.
The output window may have more diagnostic information.
Thanks.