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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:48:33+00:00 2026-05-17T14:48:33+00:00

I’m having this weird problem: when my program reach this method: //Returns the transpose

  • 0

I’m having this weird problem: when my program reach this method:

//Returns the transpose matrix of this one
RegMatrix RegMatrix::transpose() const{
    RegMatrix result(numCol,numRow);
    int i,j;
    for(i=0;i<numRow;++i)
        for(j=0;j<numCol;++j){
            result._matrix[j][i] = _matrix[i][j];
        }

        return result;
}

it suddenly crashes…

When i ran it with my VS debugger, it looked just all fine, the new matrix was filled with the relevant values, till the line return result; that from some mysterious reason returned an empty matrix vector.

Where do i go wrong??


Here is my implementation for the copy constructor:

//CCtor of RegMatrix                    
RegMatrix::RegMatrix(const RegMatrix &other): numRow(other.getRow()), numCol(other.getCol()){

    //Create
    _matrix = vector<vector<MyDouble> >(other.getRow());
    int i,j;
    for(i=0; i < numRow; i++)
        _matrix[i] = vector<MyDouble>(other.getCol());

    //Copy Matrix
    for(i=0;i<numRow; ++i){
        for(j=0;j<numCol; ++j){
            _matrix[i][j] = other._matrix[i][j];
        }
    }
}

My assignment operator implementation:

//RegMatrix = RegMatrix 
RegMatrix& RegMatrix::operator=(const RegMatrix rhs){
    assert(numRow == rhs.getRow() && numCol == rhs.getCol());
    if(*this != rhs){
        int i,j;
        for(i=0;i<numRow;++i)
            for(j=0;j<numCol;++j){
                _matrix[i][j] = rhs._matrix[i][j];
            }
    }

    return *this;
}
  • 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-17T14:48:34+00:00Added an answer on May 17, 2026 at 2:48 pm

    Assuming that MyDouble has a correct copy constructor, you should be able to reduce your copy constructor to just this:

    RegMatrix::RegMatrix(const RegMatrix &other):numRow(other.getRow()), numCol(other.getCol()),
        _matrix(other._matrix)
    { }
    

    See what that gets you.

    Edit:
    Your assignment operator might be a problem if the columns and rows aren’t equal. You’re throwing an assert in that instance, so the program is going to abort. Is that what you want? Wouldn’t you rather the assignment change the columns and rows to match the new values? If so, you can just do this:

    RegMatrix & RegMatrix::operator=(const RegMatrix & rhs) {
        if(this == &rhs)
            return *this;
        numRow = rhs.getRow();
        numCol = rhs.getCol();
        _matrix = rhs._matrix;
        return *this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put

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.