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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:46:54+00:00 2026-06-13T16:46:54+00:00

In the class Matrix typedef std::vector < std::vector <double> > TItems; class Matrix {

  • 0

In the class Matrix

typedef std::vector < std::vector <double> > TItems;
class Matrix
{
   private :
             TItems items;

   public:
           double & operator() ( int r, int c ) {return items[r][c];}
           Matrix & operator = (const Matrix A, short r1, short r2, short c1, short c2 )

}

I am trying to redefine the operator = to be able to assign a submatrix to a matrix.

Matrix  & operator = (const Matrix &A, short r1, short r2, short c1, short c2)
{
  Matrix  A_sub( r2 - r1 + 1, c2 - c1 + 1 );

  for ( int i = 0; i < ( r2 - r1 + 1 ); i++ )
  {
    for ( unsigned int j = 0; j < ( c2 - c1 + 1); j++ )
        items[i][j] = A (r1 + i, c1 + j );
  }

  return *this;
 }

But such a definition is impossible…How to fix the problem if such a type of the notation is needed?

Matrix A(8,8), B (3,9), C(3,4), D(2, 3), E (8, 8);, F(8,8)
...
A(1,3,2,5) = B (0,2,5,8) + C(0,2,0, 3) + D;
F = A + E;

Thanks for your help.

  • 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-13T16:46:55+00:00Added an answer on June 13, 2026 at 4:46 pm

    I would think the simplest solution would be to keep the same types, and just create a method that creates a smaller submatrix (still of type Matrix), copies the values in, and returns it by value.

    class Matrix {
    public:
      Matrix createSubMatrix(size_t ri, size_t ci, size_t rsz, size_t csz);
    };
    

    Then your addition, assignment, etc operations bear no additional overhead in trying to translate some other type.

    You’ll pay the overhead of the Matrix copy, but I wouldn’t stress about that at this point in your life. 🙂

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

Sidebar

Related Questions

I have the following class: template <typename T> class matrix { private: int _n;
I created a matrix class: template <typename T> class Matrix { static_assert(std::is_arithmetic<T>::value,); public: Matrix(size_t
I have a class, Matrix class Matrix { private: int cols; int rows; int
#define ROW 3 #define COL 4 class Matrix { private: int mat[ROW][COL]; //..... //.....
I'm trying to convert the following C# into F#: public class Matrix { double[,]
I created the following Matrix class: template <typename T> class Matrix { static_assert(std::is_arithmetic<T>::value,); public:
I have a matrix: #ifndef MATRIX_H #define MATRIX_H class Matrix { public: Matrix(int rows,
This is my template matrix class: template<typename T> class Matrix { public: .... Matrix<T>
Suppose I have a rather large class Matrix , and I've overloaded operator== to
I am attempting to create an overloaded operator for a matrix class that I

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.