Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7892497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:53:07+00:00 2026-06-03T06:53:07+00:00

I have an issue in my program when I’m deleting the 2d-pointer-array. I did

  • 0

I have an issue in my program when I’m deleting the 2d-pointer-array. I did search this issue but I can not see any fault in my code. I do not know what’s wrong with this code:

matrix.h:

#ifndef _MATRIX_
#define _MATRIX_

#include<iostream>
#include<string>

 using namespace std;

    template <class Type>

class Matrix {
    int line, column;
    Type** arr;

public:
    Matrix/*<Type> */(int, int);
    void print() const;
    ~Matrix/*<Type>*/();
    Type getElement (int, int) const;
    bool contains (int) const;

};

    template <class Type>
Matrix<Type> ::Matrix (int line_in, int column_in)

{ line=line_in;
  column= column_in;
  arr = new Type*[column];

   for( int i = 0 ; i < column ; i++ )
        arr[i] = new Type[line];      

    for( int i=0; i<line; i++)
        for( int j=0; j<column; j++)
            {arr[i][j]=(Type) (rand()%101)/10;
    /*cout<< arr[i][j]<<endl;*/}



}


template <class Type>
Matrix<Type>::~Matrix ()

{ 
    for(int i=0;i<column;++i)
    delete [] arr[i];
    delete [] arr;
}


template <class Type>
Type Matrix<Type>::getElement( int index_1, int index_2) const

{   string error= "Index out of bounds";
    if (index_1>line||index_2>column) throw error;
    else
    return arr[index_1-1][index_2-1];

}

 /*     template <class Type>
    void Matrix <Type>::print() const

    {   for( int i=0; i<line; i++)
          {for( int j=0; j<column; j++)
            {cout<< arr[i][j] << "  ";}
         cout<<"\n";}
    }
    */
 /*   template <class Type>
bool Matrix <Type>::contains( int number) const

{   for( int i=0; i<line; i++)
     { for( int j=0; j<column; j++)
         { if( arr[i][j]== number)
         return true;}
}
    return false;
}*/

#endif

main.cpp:

#include <iostream>
#include <ctime>
#include <string>
#include<cstdlib>
#include<conio.h>
#include"matrix.h"
using namespace std;

int main()
{
    srand(time(NULL));
Matrix<int> m1(3,5);  // creating some objects 
Matrix<int> m2(3,5);  // matrices’ elements are assigned randomly from 0 to 10
Matrix<double> m3(5,5);
Matrix<double> m4(5,6);

/*  try{
    cout << m1.getElement(3,5) << endl;   // trying to get the element at(3,6)
}
catch(const string & err_msg)
{ 
    cout << err_msg << endl;   
}*/

//cout << "Printing m4" << endl;
//m4.print();                              // printing m4

/*try{ 
    Matrix<double> m6 = m4 / m3;        // trying to divide two matrices
}
catch(const string & err_msg)
{ 
    cout << err_msg << endl;   
} */

 // cout << "Printing m1" << endl;
 // m1.print(); 

 /* if(m1.contains(4))     // checking if the matrix has an element with value 4
    cout << "Matrix contains the element" << endl;
else
    cout << "Matrix does not contain the element" << endl;*/

 /* Matrix<int> m5 = m2;
cout << "Printing m5" << endl;
m5.print();

try{
    --m1;           // decrement m1's matrix elements by 1
    m5 = m1 + m2;   // sum m1 and m2 object's matrices and assign result to m5
    ++m3;           // increment m1's matrix elements by 1
    m2 = m5 / m1;   
    if(m5 == m1)    // comparing two objects
        cout << "Objects are equal" << endl;
    else
        cout << "Objects are not equal" << endl;
}
catch(const string & err_msg)
{ 
    cout << err_msg << endl;   
}

cout << "Printing m5" << endl;
m5.print();
    }
  */

getch();

return 0;
    }

Error message on Linux:

*** glibc detected *** ./burcu.exe: free(): invalid next size (fast): 0x000000001dad6310 ***
 ======= Backtrace: =========
 /lib64/libc.so.6[0x38e3e70d7f]
/lib64/libc.so.6(cfree+0x4b)[0x38e3e711db]
./burcu.exe[0x400c45]
./burcu.exe(__gxx_personality_v0+0x1f0)[0x400908]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x38e3e1d994]
./burcu.exe(__gxx_personality_v0+0x61)[0x400779]
======= Memory map: ========
 00400000-00401000 r-xp 00000000 00:16 28050037                           /users/lnxsrv1/ee/akgunhas/burcu3/burcu.exe
 00601000-00602000 rw-p 00001000 00:16 28050037                           /users/lnxsrv1   /ee/akgunhas/burcu3/burcu.exe
1dad6000-1daf7000 rw-p 1dad6000 00:00 0 
38e3a00000-38e3a1c000 r-xp 00000000 fd:00 1593483                        /lib64/ld-2.5.so
38e3c1c000-38e3c1d000 r--p 0001c000 fd:00 1593483                        /lib64/ld-2.5.so
38e3c1d000-38e3c1e000 rw-p 0001d000 fd:00 1593483                        /lib64/ld-2.5.so
38e3e00000-38e3f4d000 r-xp 00000000 fd:00 32363                          /lib64/libc-2.5.so
38e3f4d000-38e414d000 ---p 0014d000 fd:00 32363                          /lib64/libc-2.5.so
38e414d000-38e4151000 r--p 0014d000 fd:00 32363                          /lib64/libc-2.5.so
38e4151000-38e4152000 rw-p 00151000 fd:00 32363                          /lib64/libc-2.5.so
38e4152000-38e4157000 rw-p 38e4152000 00:00 0 
38e4200000-38e4282000 r-xp 00000000 fd:00 291216                         /lib64/libm-2.5.so
38e4282000-38e4481000 ---p 00082000 fd:00 291216                         /lib64/libm-2.5.so
38e4481000-38e4482000 r--p 00081000 fd:00 291216                         /lib64/libm-2.5.so
38e4482000-38e4483000 rw-p 00082000 fd:00 291216                         /lib64/libm-2.5.so
38e7a00000-38e7a0d000 r-xp 00000000 fd:00 291213                         /lib64/libgcc_s-4.1.2-20080825.so.1
38e7a0d000-38e7c0d000 ---p 0000d000 fd:00 291213                         /lib64/libgcc_s-   4.1.2-20080825.so.1
 38e7c0d000-38e7c0e000 rw-p 0000d000 fd:00 291213                         /lib64/libgcc_s-   4.1.2-20080825.so.1
38eae00000-38eaee6000 r-xp 00000000 fd:00 785480                         /usr/lib64/libstdc++.so.6.0.8
38eaee6000-38eb0e5000 ---p 000e6000 fd:00 785480                         /usr/lib64/libstdc++.so.6.0.8
38eb0e5000-38eb0eb000 r--p 000e5000 fd:00 785480                         /usr/lib64/libstdc++.so.6.0.8
38eb0eb000-38eb0ee000 rw-p 000eb000 fd:00 785480                         /usr/lib64       /libstdc++.so.6.0.8
38eb0ee000-38eb100000 rw-p 38eb0ee000 00:00 0 
2abb21ac1000-2abb21ac3000 rw-p 2abb21ac1000 00:00 0 
2abb21ad9000-2abb21adb000 rw-p 2abb21ad9000 00:00 0 
7fff72e31000-7fff72e46000 rw-p 7ffffffe9000 00:00 0                      [stack]
7fff72f24000-7fff72f27000 r-xp 7fff72f24000 00:00 0                      [vdso]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0                  [vsyscall]
Aborted

in VS 2010:

HEAP[burcuhw3.exe]: Heap block at 001738B0 modified at 00173904 past requested size of 4c
Windows has triggered a breakpoint in burcuhw3.exe.

This may be due to a corruption of the heap, which indicates a bug in burcuhw3.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while burcuhw3.exe has focus.

The output window may have more diagnostic information.
The program '[1320] burcuhw3.exe: Native' has exited with code 0 (0x0).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:53:09+00:00Added an answer on June 3, 2026 at 6:53 am

    Seems like the internal data is allocated in the constructor as arr[column][line] and then used as arr[line][column]. That would be a problem!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue with a simple program. I'm opening a QFileDialog this way:
Hi I have to resolve an issue in this program. I don't know why
I have a very odd issue trying to run this quite simple C program
I have run into a small issue in my program. I have a class
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
i have a bizzare issue with a program ive written where the command File.Exists()
I have an issue right now with a program im trying to create. The
I have a C program for an exercise and it has a strange issue
I have a 3 file program, basically teaching myself c++. I have an issue.
So i have this issue : i am declaring some extern global variables in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.