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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:29:27+00:00 2026-05-30T22:29:27+00:00

This is a function within my doubly linked list class, but every time I

  • 0

This is a function within my doubly linked list class, but every time I compile, I get this message: “Invalid initialization of non-const reference of type ‘int&’ from a temporary of type ‘int’. I just can’t get how else to do it.

int& LinkedList::operator[](int index)
{
    Node* current = head_;

    for(int i = 0; i < index; i++){
        current = current->getNextNode();
    }

    return(current->getValue()); // getValue() returns an int
} 

Thanks in advance!

  • 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-30T22:29:29+00:00Added an answer on May 30, 2026 at 10:29 pm

    Simple answer: getValue has to return an int& as well.

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

Sidebar

Related Questions

Can I pass this to a function as a pointer, from within the class
I had a function like this, that wasn't within a class: // Gets the
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
Having issues referencing $(this) from within a the nested ajax 'success' function... I know
I'm invoking a C++ function from within C#. This is the function header in
I have a doubly linked list in C and I'm confused as to how
So I have this ASP.Net 2.0 website that uses functions contained within a JS
This blog says Include Return Statements with in the Function/Method. How it improves performance
This function appears to be a way to access all sorts of system values.
This function declaration gives me errors: ostream& operator<<(ostream& os, hand& obj); The errors are:

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.