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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:29:02+00:00 2026-06-03T19:29:02+00:00

I was trying to learn some operator overloading methods on C++ then I had

  • 0

I was trying to learn some operator overloading methods on C++ then I had this error :

Error 7 error C2228: left of ‘.values’ must have class/struct/union

There is also another error that says :

Error 4 error C2065: ‘sum’ : undeclared identifier

Matrix<type> Matrix<type>::operator+(const Matrix& m){

    if(num_of_rows != m.num_of_rows || num_of_cols != m.num_of_cols) // Checking if they don't have the same size.

    Matrix<type> *sum;
    sum = new Matrix<type>(num_of_rows, num_of_cols);

    for(int i = 0; i < num_of_rows; i++)
        for(int j = 0; j < num_of_cols; j++)
            sum.values[i][j] =  values[i][j] + m.values[i][j];

    return *sum;
}

Can someone tell me where I did wrong?

  • 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-03T19:29:09+00:00Added an answer on June 3, 2026 at 7:29 pm

    In the code you have posted, sum is a pointer. Therefore, to access the members of the object, you need to use ->:

    sum->values[i][j] = ...
    

    You also seem to be missing a semicolon after the declaration Matrix<type> *sum;, but it’s unclear whether that is a transcription error or whether your code really looks like that.

    Finally, your memory management leaks an object. You allocate an object with new, but return a copy of that object, and never free it. Perhaps you want something like:

    Matrix<type> sum(num_of_rows, num_of_cols);
    
    for ( ... )
        sum.values[i][j] = ..
    
    return sum;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a little PDO CRUD to learn some PDO. I have
I'm trying to learn some OpenGL via this tutorial . My question is regarding
Greetings, I am currently trying to learn some Java programming. To do this I'm
I'm trying to learn some programming with jQuery. I have a div that has
Ok so I am just trying to learn some of this fun stuff now,
i know virtually no java but i'm trying to learn some for this project.
I'm trying to learn some javascript and have gotten stuck. Right now, I have
I'm trying to learn some PHP, and I've been banging my head against this
I am new to PHP and trying to learn some so sorry if this
I'm trying to learn some Rails but I seem to get stuck on this

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.