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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:22:10+00:00 2026-06-12T12:22:10+00:00

I wrote an IntegerMatrix class to add my own methods to work with matrices.

  • 0

I wrote an IntegerMatrix class to add my own methods to work with matrices. Now I’ve written a function like this:

IntegerMatrix** IntegerMatrix::multiplyMatrix(IntegerMatrix** table2)

(It’s a double pointer because I’m holding a huge array of pointers to 4×4 2D arrays.) so I simply could do this:

matrix1.multplyMatrix(matrix2)

One little problem is the * isn’t defined for my own class. So I thought to overload this operator that I could do something like this:

sum += this->table[i][k] * table2[k][j];

But how can I get the right i and k in the overloaded operator, which is defined like this:

IntegerMatrix IntegerMatrix::operator*(const IntegerMatrix & k);

The only problem I can’t figure out right now is how to get the right values ?

EDIT:

I’ve rewrote this and now I have:

IntegerMatrix IntegerMatrix::operator*(const IntegerMatrix & table2)
{
    int i, j, k;
    int sum;
    IntegerMatrix * result = new IntegerMatrix(SIZE);

    for (i = 0; i < SIZE; i++) {
        for (j = 0; j < SIZE; j++) {
            sum = 0;
            for (k = 0; k < SIZE; k++) {
                sum += this->table[i][k] * table2[k][j];
            }
            result[i][j] = sum;
        }
    }
    return *result;

}

That gives me just an error on the [] :

Binary '[' : 'IntegerMatrix' does not define this operator or a conversiont o a type acceptable to the predefined operator.
  • 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-12T12:22:11+00:00Added an answer on June 12, 2026 at 12:22 pm

    I don’t understand your question, but here’s a brief demo of how matrix multiplication normall works:

    class IntegerMatrix {
        int table[3][3];
    
    public:
          IntegerMatrix& operator*=(const IntegerMatrix& rhs) {
               //multiply table by rhs.table, store in data.
               return *this;
          }
    };
    IntegerMatrix operator*(IntegerMatrix lhs, const IntegerMatrix& rhs)
    {return lhs*=rhs;} //lhs is a copy, so we can alter and return it
    

    FOR YOUR EDIT

    You have the code

    IntegerMatrix * result = new IntegerMatrix(SIZE); //pointer to an IntegerMatrix
    ...
    result[i][j] = sum; //assign sum to the jth index of matrix # i
    

    when in actuality, I presume you wanted

    result->table[i][j] = sum; //sum to the ixj index of the result matrix.
    

    Also, your function is leaky, because you have a new, but no delete. This is easy to fix in your case, since you don’t need the new. (Are you from a Java or C# background?)

    IntegerMatrix result(SIZE);
    ...
            result[i][j] = sum;
    ...
    return result;
    

    Unrelated to all of the above, you might actually want to provide a [] operator for your Integer Matrix.

    class row {
        int* data;
        int size;
    public:
        row(int* d, int s) :data(d), size(s) {}
        int& operator[](int offset) {
            assert(offset<size);
            return data[offset];
        }
    };
    
    row operator[](int column) {
        assert(column<SIZE); 
        return row(table[column], SIZE);
    }
    

    And this would allow you to write:

    IntegerMatrix result;
    result[i][j] = sum;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this function to swap values in a multi-dimensional array with my understanding
I wrote this short test code, but it didn't work. What am I doing
I wrote this function in javascript function CheckBeforeAddNew(btnId, gridSelected) { $(btnId).click(function () { for
I wrote a process explorer using C with GUI interface. I want to add
I wrote a collada loader for my model viewer. Write now it loops through
i wrote a program that get data from user and store it in database.this
I wrote the following Ruby code file: require 'MyAssembly.dll' class MyClass def initialize(obj) System::Diagnostics::WriteLine('test')
I wrote a trajectory planner in Matlab, and I would like to compile as
I wrote this method (almost similar in other post) public void update(string fileName, string
I wrote this code app = Tk() app.title('Myapp') app.geometry('260x100+50+50') labelText =StringVar() labelText.set('Insert the version

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.