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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:36:38+00:00 2026-06-12T03:36:38+00:00

Alright, I’m trying to figure out this error and have, so far, had absolutely

  • 0

Alright, I’m trying to figure out this error and have, so far, had absolutely no luck. I’m doing this for homework, which is why I’m not using included classes.

Here’s the relevant code:

//Will return an array where each element is the sum of the respective sums in the added         arrays
Vec& Vec::operator+(Vec& v2) const{
    Vec ret();
    if(mySize>0){
        Vec ret(mySize);
        for(unsigned i = 0;i<mySize;i++){
            ret[i]=v2[i]+myArray[i];
        }
    }
    else{
    }
    return ret;
}

And from the .h file…:

Vec& operator+ (Vec& v2) const;

This throws the error: “invalid initialization of non-const reference of type ‘Vec&’ from an rvalue of type ‘Vec (*)()’”
I’m completely new to C++, so any help would be appreciated.

  • 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-12T03:36:40+00:00Added an answer on June 12, 2026 at 3:36 am
    Vec ret();
    

    Is taken to be a forward declaration of a function which takes no arguments and returns a Vec. See: the most vexing parse.

    Next, you’re returning a reference to a local variable, which is bad. ret goes out of scope as soon as the function returns.

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

Sidebar

Related Questions

Alright, I'm trying to figure out why I can't understand how to do this
Alright so I have no idea how to even begin doing this But basically
Alright, this one's got me seriously stumped, after trying things out for hours with
Alright here is the thing, I have this site that was once wordpress but
Alright so i have been working on this Dynamic load of a spinner from
Alright. This may be difficult but I have been struggling for quite a bit
Alright I've been debugging the whole day but can't figure out what the problem
Alright, this problem seems to be way above my head! I have this code:
Alright, i have read many different views on how to do this with no
Alright, here is my problem i'm trying to solve. I have an index page

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.