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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:31:10+00:00 2026-06-14T22:31:10+00:00

I have a Matrix class and I overlap the basic operations template<class T> Matrix<T>::Matrix(unsigned

  • 0

I have a Matrix class and I overlap the basic operations

template<class T>
Matrix<T>::Matrix(unsigned rows, unsigned cols) :
        rows_(rows), cols_(cols) {
    index = 0;
    data_.reserve(rows * cols);
}
template<class T>
Matrix<T> Matrix<T>::operator=(const Matrix<T>& m) {

    rows_ = m.rows();
    cols_ = m.cols();
    index = 0;

    data_ =  m.data_;
    return *this;
}

But when I’m using the equal operator I’m getting strange values:

Matrix<double> a(5, 5);
Matrix<double> b(2, 2);
a << 5, 2, 4, 5, 6, 1, 3, 1, 2, 5, 2, 5, 2, 7, 2, 9, 2, 1, 0.1, 0.43, 1, 0, 0, 0, 1;
a.print("a");
b = a;
b.print("B");

The output:

a
5   2   4   5   6   
1   3   1   2   5   
2   5   2   7   2   
9   2   1   0.1 0.43    
1   0   0   0   1   
B
0   0   0   0   0   
2.42092e-322    4.94066e-324    4.94066e-324    0   3.26083e-322    
0   6.66322e-319    0   0   0   
0   0   0   0   0   
0   0   0   0   0

Why is it like 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-06-14T22:31:11+00:00Added an answer on June 14, 2026 at 10:31 pm

    It looks as if you meant to use resize() rather than reserve(): the former actually changes the size of the std::vector<double> while the latter just arranges for enough space to be present but it doesn’t put any objects inside nor does it copy the content.

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

Sidebar

Related Questions

I have a matrix class and, with the following constructor: template<class T> Matrix<T>::Matrix(unsigned rows,
I have a class, Matrix class Matrix { private: int cols; int rows; int
I have a matrix class with the size determined by template parameters. template <unsigned
I have the following class: template <typename T> class matrix { private: int _n;
We have two classes: template<typename T, typename Size, typename Stack, typename Sparse> class Matrix
I have a SquareMatrix template class which inherits Matrix template class, like below: SquareMatrix.h:
I have a matrix class defined this way: template<int M, int N, typename T>
I have a matrix class like below: template <size_t M, size_t N, typename T>
I've been implementing a custom template matrix class and I have a function I
I have a matrix: #ifndef MATRIX_H #define MATRIX_H class Matrix { public: Matrix(int rows,

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.