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

  • Home
  • SEARCH
  • 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 7648009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:36:12+00:00 2026-05-31T10:36:12+00:00

I have a simple matrix class which has a 2d integer pointer field in

  • 0

I have a simple matrix class which has a 2d integer pointer field in it. When I call following function multiple times, it gives me a glibc error on Linux machine. When I have “otherM.value = ‘\0’;” add this line to the end of function, problem resolves. Could somebody explain me why I have this dangling pointer issue, although class is passed by copy, not by reference? Pointer members are passed by reference?

void matrix::sub(matrix otherM)
{
if(dimX!=otherM.dimX || dimY!=otherM.dimY)
    return;

int** rowPtr = value;   
int** otherMrowPtr = otherM.value;

for(int i=0;i<dimX;i++){
    for(int j=0;j<dimY;j++){                        
        (**rowPtr) = (**rowPtr) - (**otherMrowPtr);
        (*rowPtr)++;
        (*otherMrowPtr)++;
    }
    (*rowPtr)-=dimY;
    (*otherMrowPtr)-=dimY;

    rowPtr++;
    otherMrowPtr++;
}

rowPtr = '\0';
otherMrowPtr = '\0';

otherM.value = '\0';

}

matrix::matrix(int x, int y){

dimX = x;
dimY = y;
// allocate here 
value = new int*[dimX];
int** rowPtr = value;
for(int i=0;i<dimX;i++){
    *rowPtr = new int[dimY];
    rowPtr++;
}
}

matrix::~matrix(){
if(value!=NULL){
    int** rowPtr = value;   
    for(int i=0;i<dimX;i++){
            delete[] (*rowPtr);
            rowPtr++;
    }
    rowPtr-=dimX;
    delete[] rowPtr;
    rowPtr = '\0';
}
value = '\0';
}
  • 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-05-31T10:36:14+00:00Added an answer on May 31, 2026 at 10:36 am

    Did you implement copy constructor, assignment operator and destructor for your class? If not then go and implement those since you’re managing a resource.

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

Sidebar

Related Questions

I've been implementing a custom template matrix class and I have a function I
I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package in which On Error event handler I have created
I have some simple code that represents a graph using a square boolean matrix
Let's assume that we have a simple matrix 3rows x 7cols. The matrix includes
A simple matrix benchmark test has indicated that Revolution Analytics R 2.13.2 's LU
We have a simple table with say (nxm matrix) and the user will randomly
I'm doing a project for a class which focuses on storing a huge matrix
I have this simple graph: name -> string ^ | v label let matrix
I have an xts numeric matrix on which I need to apply many transformations.

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.