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 8337851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:24:49+00:00 2026-06-09T04:24:49+00:00

I have a class, Matrix class Matrix { private: int cols; int rows; int

  • 0

I have a class, Matrix

class Matrix
{
private:
    int cols;
    int rows;
    int **matrix;
public:
    //constructors and methods
    friend Matrix addandupdate(Matrix a, Matrix b); 
}

I have the function addandupdate defined outside as below,

Matrix addandupdate(Matrix a, Matrix b)
{
    int rsize = a.rows;
    int csize = a.cols;

    Matrix c(csize, rsize);

    for(int i=0; i<rsize; i++)
    {
        for(int j=0; j<csize; j++)
        {
            c.set(i,j,a.matrix[i][j]+b.matrix[i][j]);
        }
    }
    return c;
}

Then in main,

Matrix x(c, r);
//filling values in x
//printing x
Matrix newx = addandupdate(x, x);    //something is not right here
//printing newx

Everything is fine except the line above that is causing to throw a runtime error.

*** glibc detected *** ./a.out: munmap_chunk(): invalid pointer: 0x085c6020 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x73e42)[0x183e42]
/lib/i386-linux-gnu/libc.so.6(+0x74525)[0x184525]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0x84d51f]
./a.out[0x8048c69]
./a.out[0x8048b05]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x1294d3]
./a.out[0x8048751]

I’m writing C++ code after a long time. Please excuse me if it’s something silly.

  • 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-09T04:24:50+00:00Added an answer on June 9, 2026 at 4:24 am

    Matrix newx = addandupdate(x, x); calls the copy constructor, which you haven’t implemented, and you need since a shallow copy isn’t enough in your case.

    You’ll also need an assignment operator and destructor.

    Or, as Mark pointed out, replace int **matrix; with std::vector<std::vector<int> >.

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

Sidebar

Related Questions

I have a matrix: #ifndef MATRIX_H #define MATRIX_H class Matrix { public: Matrix(int rows,
I have the following class: template <typename T> class matrix { private: int _n;
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have class with back reference: public class Employee : Entity { private string
#define ROW 3 #define COL 4 class Matrix { private: int mat[ROW][COL]; //..... //.....
I have a class that wraps logic for matrix management. Meanwhile I have a
I have a code base, in which for Matrix class, these two definitions are
Is there a way to have a matrix of user-defined type in OpenCV 2.x?
I have a class template<size_t N, size_t M> class Matrix { // .... };
I have a matrix class that takes the row and column reference type that

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.