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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:14:17+00:00 2026-06-09T11:14:17+00:00

I get the Invalid initialization of non-const reference of type ‘std::vector&’ from an rvalue

  • 0

I get the “”Invalid initialization of non-const reference of type ‘std::vector&’ from an rvalue of type ‘std::vector” error for the last last for passing in merge_sort(right) in the 2nd param.

left_merged = merge_sort(left);
// right_merged = merge_sort(right);
return merge(left_merged, merge_sort(right));

Here are the function declarations:

vector<int> merge_sort(vector<int>& vec)
vector<int> merge(vector<int>& left, vector<int>& right) 

I’ve been reading up the theory on how the rvalue is a temporary object and is destroyed if it’s not used in an initializer or assigned to a variable but all I really want is a quick and dirty solution to be able to call the function in the parameter.

Any quick solutions?

Thanks!

  • 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-09T11:14:19+00:00Added an answer on June 9, 2026 at 11:14 am

    Change the parameter type, either to const vector<int>& (const reference), or simply vector<int> (by value).

    Prefer the first option (const reference) if inside the function you don’t make any changes to the parameter. Otherwise the second (by value). If, inside the function, you are immediately copying the argument, and then manipulating the copy while ignoring the original, take the argument by value, skip the copy, and just use the argument directly.

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

Sidebar

Related Questions

Initializing in the header file i get the following error: invalid in-class initialization of
when I seem to use parameters in my query, I get an error Invalid
I get the following error when running the code below: invalid byte sequence in
I get error: ORA-06575: Package or function GET_CONC_NAMES is in an invalid state When
When I launch my emulator, I get the following error: invalid command-line parameter: Android
For example typing: localhost:3000/absurd-non-existing-route How do I get invalid routes to point to the
Using Boost 1_33_1, I get an error implying that my iterator is a const
This script works well in MVC 1, however I get invalid arguments error in
I get invalid label error for firstname: John2, . I put my json data
I want to redirect to home page if session get invalid. My spring-servlet.xml is

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.