Returning by reference

This is a discussion on Returning by reference within the C++ Programming forums, part of the General Programming Boards category; Hi, i have a question, so suppose you have a function and it had a return value that was a ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    70

    Returning by reference

    Hi, i have a question, so suppose you have a function and it had a return value that was a reference like int& foo(), why would you return an int instead of a int& like the return value says we're suppose to return??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You say it right in your title -- you are returning an int by reference, not returning a reference-to-int. (EDIT: To say it perhaps a different way, there's not really a different "type" involved -- an int& can't exist in isolation, it must be a reference to an actually-existing int.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21