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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:05:07+00:00 2026-06-15T02:05:07+00:00

When I try to use this line in main.cpp: m3.array = m1.array+m2.array; where m3,

  • 0

When I try to use this line in main.cpp:

m3.array = m1.array+m2.array;

where m3, m1, and m2 are all objects of a class type Matrix, with an int[3][3] array –
I keep getting an error that deals with an incompatible assignment of type int[3][3] and int[3][3] to opperand ‘+’. I don’t know the exact error, because I’m not at a computer to compile the program.

Here’s the matrix.cpp I have:

#include <iostream>
#include <string>
#include "matrix.h"

using namespace std;

Matrix::Matrix()
{
    m1.array = 0;
}

istream& opeator >>(istream& inp, Matrix& m1)
{
         int i, j;

         for (i = 0; i < 3;i++)
         {
             for (j=0; j < 3;j++)
             {
                 inp >> m1.array[i][j];
             }
         }
         return inp;
}
ostream& operator <<(istream& outp, Matrix& m1)
{
         int i, j;
         for (i = 0;i<3;i++)
         {
             for (j = 0;j<3;j++)
             {
                 out<<m1.array[i][j]<<" "<<endl;
             }
         }
         return outp;
}

Matrix operator + (const Matrix& m1, const Matrix& m2)
{
        Matrix answer;
        int i,j;
        for (i = 0;i<3;i++)
        {
            for (j = 0;j<3;j++)
            {
                answer.array[i][j] = m1.array[i][j] + m2.array[i][j];
            }
        }
        return answer;
}

Matrix operator - (const Matrix& m1, const Matrix& m2)
{
        Matrix answer;
        int i, j;
        for (i = 0;i<3;i++)
        {
            for (j = 0;j<3;j++)
            {
                answer.array[i][j] = m1.array[i][j] - m2.array[i][j];
            }
        }
        return answer;
}

Matrix operator * (const Matrix& m1, const matrix& m2)
{
       Matrix answer;
       int i, j, k;
       for (i = 0;i<3;i++)
       {
           for (j = 0; j<3;j++)
           {
               for (k = 0; k<3;k++)
               {
                   answer.array[i][j] = m1.array[i][k] + m2.array[k][j];
               }
           }
       }
       return answer;
}

and the matrix.h:

#ifndef MATRIX_H
#define MATRIX_H

using namespace std;

class Matrix
{
      public:
             Matrix();
             friend istream& operator >>(istream&, Matrix&);
             friend ostream& operator <<(ostream&, const Matrix&);
             friend Matrix& operator +(const Matrix&, const Matrix&);
             friend Matrix& operator -(const Matrix&, const Matrix&);
             friend Matrix& operator *(const Matrix&, const Matrix&);
             int array[3][3];

};




#endif
  • 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-15T02:05:09+00:00Added an answer on June 15, 2026 at 2:05 am
    Matrix operator + (const Matrix& m1, const Matrix& m2)
    

    This tells the computer how to add two Matrix objects, good job.

    m3.array = m1.array+m2.array;
    

    m1 and m2 are Matrix objects, but m1.array is not. That is a int[3][3] object. Luckily, the fix is very very simple:

    m3 = m1 + m2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to use TBXML and getting this error TBXML class method +tbXMLWithURL not
I'm getting a classCastException every time I try to use this preference class, and
When I try to use this in my Javascript prototype like so: Array.prototype.sample =
I try to update my profile image and use this code: $connection->post('account/update_profile_image', array('image' =>
I try to use the boolean in my class and get this message reference
I'm getting an error in Netbeans in my driver class on this line: System.out.print(Time
When I use this line of code in the viewDidLoad of the app's main
I try to use this: xml2struct when I use this xml: <XMLname attrib1=Some value>
I try to use this mapping : @Entity @Table(name=ecc.\RATE\) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=DISCRIMINATOR, discriminatorType= DiscriminatorType.STRING) public
Many people use this method to add animation on switching views. When I try

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.