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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:43:18+00:00 2026-05-27T13:43:18+00:00

Could somebody please explain me wth is wrong with my operators: Matrix3D Matrix3D::operator*(Matrix3D& m)

  • 0

Could somebody please explain me wth is wrong with my operators:

Matrix3D Matrix3D::operator*(Matrix3D& m) {
    Matrix3D ret;
    for(int i=0;i<4;i++) {
        for(int j=0;j<4;j++) {
            ret._data[i][j]=0.0;
            for(int k=0;k<4;k++) {
                ret._data[i][j] += (this->_data[i][k]*m._data[k][j]);
            }
        }
    }
    return ret;
}

Matrix3D& Matrix3D::operator=(Matrix3D& m) {
    if(this==&m) {
        return *this;
    }
    for(int i=0;i<4;i++) {
        for(int j=0;j<4;j++) {
            this->_data[i][j] = m._data[i][j];
        }
    }
    return *this;
}

Matrix3D Matrix3D::Rotation(double ax, double ay, double az) {
    Matrix3D rotX;
    Matrix3D rotY;
    Matrix3D rotZ;
    rotX(
        1,          0,          0,          0,
        0,          cos(ax),    -sin(ax),   0,
        0,          sin(ax),    cos(ax),    0,
        0,          0,          0,          1
    );
    rotY(
        cos(ay),    0,          sin(ay),    0,
        0,          1,          0,          0,
        -sin(ay),   0,          cos(ay),    0,
        0,          0,          0,          1
    );
    rotZ(
        cos(az),    -sin(az),   0,          0,
        sin(az),    cos(az),    0,          0,
        0,          0,          1,          0,
        0,          0,          0,          1
    );

    // Matrix3D ret;
    // ret = rotX*rotY*rotZ;
    // This doesn't work
    // C:\(...)\Matrix3D.cpp|100|error: no match for 'operator=' in 'ret = Matrix3D::operator*(Matrix3D&)(((Matrix3D&)(& rotZ)))'|

    // however this does work

    Matrix3D ret = rotX*rotY*rotZ;
    return ret;
}

as stated in the code above, something like

    Matrix3D ret;
    ret = rotX*rotY*rotZ;

will result in

    C:\(...)\Matrix3D.cpp|100|error: no match for 'operator=' in 'ret = Matrix3D::operator*(Matrix3D&)(((Matrix3D&)(& rotZ)))'|

compilation error, while something like

    Matrix3D ret = rotX*rotY*rotZ;

will compile without any warning or error whatsoever (don’t know if the matrixes are right tho, haven’t checked that yet…).

  • 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-05-27T13:43:19+00:00Added an answer on May 27, 2026 at 1:43 pm

    Actually, both operators are declared wrongly. They should take a const reference to allow rvalues be accepted.

    Matrix3D Matrix3D::operator*(const Matrix3D& m) const
    //                           ^^^^^              ^^^^^
    //                                              this too, since you're not
    //                                              changing the LHS during '*'.
    
    Matrix3D& Matrix3D::operator=(const Matrix3D& m)
    //                            ^^^^^
    

    You’ll see that * doesn’t work with rotX*(rotY*rotZ).

    The reason Matrix3D ret = rotX*rotY*rotZ; compiles is because the operator= is not invoked at all. It just calls the copy constructor of Matrix3D to the result of the multiplication. And the multiplication works because rotX * rotY * rotZ is rewritten to

    rotX.operator*(rotY).operator*(rotZ)
    

    and rotY and rotZ are both lvalues, so they can be bound to Matrix3D&.

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

Sidebar

Related Questions

Could somebody please explain the meaning of this error? INFO: Scanning for root resource
Could somebody please explain to me why does this code only print 42 instead
Could somebody please explain this piece of Ruby code: def add_spec_path_to(args) # :nodoc: args
Could somebody please explain this to me. It seems to me that the number
Could somebody please explain what GCC is doing for this piece of code? What
could somebody please explain why this happens? I have written the following: 1) a
Could somebody please explain to me what happens here? I am creating a binding
Could somebody please name a few. I could given time, but this is for
Could somebody please explain why the variable named foo remains true in the code
Could somebody please explain why I'm getting a compile error here - error C2558:

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.