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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:25:02+00:00 2026-06-02T20:25:02+00:00

I have a matrix: #ifndef MATRIX_H #define MATRIX_H class Matrix { public: Matrix(int rows,

  • 0

I have a matrix:

#ifndef MATRIX_H
#define MATRIX_H

class Matrix
{   
    public:
        Matrix(int rows, int columns);
        Matrix(int, int, int** matrix); 
        Matrix(Matrix* copy);
        ~Matrix();

        void Set(int, int, int);
        void SetMatrix(int, int, int** matrix);             
        void Print();
        void ZeroMatrix(int,int,int** matrix);      
        void Add(Matrix* B);
        void Subtract(Matrix* B);
        void Copy(Matrix* B);

        int** Multiply(Matrix* B);
        int** Create(int,int);
        int** Get();
        int** Transpose();
        int** Scalar(int);

        int Get(int,int);
        int Rows();
        int Columns();

        Matrix operator*(int);

    private:
        int** _matrix;
        int _rows;
        int _columns;
};

#endif

Here’s the implementation:

Matrix Matrix::operator*(int scale)
{
    return Matrix(_rows, _columns, Scalar(scale));
}

And for a school assignment we have to overload the multiple operator to work with integer scalar. The problem is I keep getting this error:

main.cpp: In function ‘int main(int, char*)’:
main.cpp:18:15: error: no match for ‘operator
’ in ‘4 * B’

Breaking code:

#include "Matrix.h"
#include <fstream>
#include <iostream>

int main(int argc, char *argv[])
{   
    Matrix* A = new Matrix(4,2);

    A->Set(0,0,1);  
    A->Set(0,1,2);
    A->Set(1,0,3);
    A->Set(1,1,4);  
    A->Print();

    Matrix B(A);
    B.Print();

    Matrix C(4 * B); //this line
    C.Print();


    delete A;

    return 0;
}

Any ideas?

edit # 1:

the code:

Matrix operator*(int); 
        Matrix operator* (int, const Matrix &);

generates:

In file included from main.cpp:1:0:
Matrix.h:31:40: error: ‘Matrix Matrix::operator*(int, const Matrix&)’ must take either zero or one argument
In file included from matrix.cpp:1:0:
Matrix.h:31:40: error: ‘Matrix Matrix::operator*(int, const Matrix&)’ must take either zero or one argument
matrix.cpp:207:50: error: ‘Matrix Matrix::operator*(int, const Matrix&)’ must take either zero or one argument
  • 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-02T20:25:04+00:00Added an answer on June 2, 2026 at 8:25 pm

    When you specify your member function, your class must be the left hand side.

    B * 4 is equivalent to B.operator* (4). When you say 4 * B, this does not work.

    To remedy this, simply use B * 4 instead of 4 * B, or provide an external overload

    Matrix operator* (int, const Matrix &);
    

    Then, the 4 * B will match this overload.

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

Sidebar

Related Questions

I have a matrix with n columns, n rows and every element is initialized
I have a matrix like the following (arbitrary cols/rows): 1 0 0 0 0
I am trying to create a Matrix class using c++. So far, I have
I have a SquareMatrix template class which inherits Matrix template class, like below: SquareMatrix.h:
Hey! I have matrix class and i want to add, multiply and take transpose
I have a matrix and a vector each with 3000 rows: fe = [-0.1850
I have a matrix in SQL reporting and I would like it to print
I have a matrix class with the size determined by template parameters. template <unsigned
I have a matrix which is built at the start of the class and
I have a Matrix class and I want to pass an array to the

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.