implicit passing by reference

Discussion in 'C++' started by jerry.jeremiah, Feb 21, 2014.

  1. In this topic

    http://stackoverflow.com/questions/...-why-my-for-loop-will-not-count-all-the-way-u

    The person that answers it says:

    You have to remember that objects are sent to functions 'by reference'.

    But the object being passed contains only one int member and the function the object is being passed to clearly takes it's parameter by value and stores it in a member value.

    Do objects really always pass by reference regardless of what the parameter list says? And, if so, why would it do that? I would usderstand if the function took its parameter explicitly by reference...

    Thanks for clearing up mu confusion.

    Jerry
     
    jerry.jeremiah, Feb 21, 2014
    #1
    1. Advertisements

  2. jerry.jeremiah

    Jorgen Grahn Guest

    Or you could say it's always by value -- but you can choose to pass a
    reference or pointer to some object.
    Yes, and you have to be pretty confused to do that.
    I tell my coworkers to avoid stackoverflow because of stuff like
    this.

    /Jorgen
     
    Jorgen Grahn, Feb 21, 2014
    #2
    1. Advertisements

  3. Strictly speaking it is up to the platform how references are
    implemented. The option that they are binary compatible to pointers is
    only a common solution.
    Well, in general it is not that bad. But it is more the home of the .NET
    guys (where the statement about objects is true) and like any other
    forum it is no editorially approved content.


    Marcel
     
    Marcel Müller, Feb 21, 2014
    #3
  4. Well, an object in C++ has some hidden
    field to store the address of this object in the C sense.
     
    88888 Dihedral, Feb 21, 2014
    #4
  5. I will probably regret this later, but... What the hell do you mean?

    V
     
    Victor Bazarov, Feb 21, 2014
    #5
  6. jerry.jeremiah

    Osmium Guest

    Now you did it. You reactivated him after a long dormant period.
     
    Osmium, Feb 21, 2014
    #6
  7. I did? Damn... I thought he was replying to Paavo. Ah, no matter.
    Sorry! My fault! I really regret this! Etc. etc.

    V
     
    Victor Bazarov, Feb 21, 2014
    #7
  8. jerry.jeremiah

    red floyd Guest

    You are hereby sentenced to 200 hours of listening to Justin Bieber
    albums.
     
    red floyd, Feb 21, 2014
    #8
  9. jerry.jeremiah

    Ian Collins Guest

    That, being a cruel and inhumane punishment, would be considered a
    breach of Victor's human rights by the European court :)
     
    Ian Collins, Feb 22, 2014
    #9
  10. I still probably deserve it. Besides, I don't reside in the
    jurisdiction of the European court :-[

    V
     
    Victor Bazarov, Feb 22, 2014
    #10
  11. jerry.jeremiah

    red floyd Guest

    Just giving you a hard time, Victor. The opportunity was too good
    to pass up. :-D
     
    red floyd, Feb 22, 2014
    #11
  12. jerry.jeremiah

    Jorgen Grahn Guest

    Of course. Note that I didn't imply that references are pointers --
    just that both can be used if you want "pass by reference" semantics.

    /Jorgen
     
    Jorgen Grahn, Feb 22, 2014
    #12
  13. jerry.jeremiah

    James Kanze Guest

    You've noticed that too. The highest ranked answers are rarely
    the correct ones.
     
    James Kanze, Feb 23, 2014
    #13
  14. jerry.jeremiah

    James Kanze Guest

    It's harder to do if you work in an investment bank, where NNTP
    is blocked by the firewall, as is Google Groups. (I have yet to
    figure out the reasoning behind it, but it seems to be some
    legal requirement, since it is univeral, at least in London
    banks.)
     
    James Kanze, Feb 23, 2014
    #14
  15. jerry.jeremiah

    Stefan Ram Guest

    Read the post »Welcome Slashdot refugees!« of February 6 in
    the newsgroup »comp.misc« and the following posts to witness
    the return of Slashdot users to Usenet.
     
    Stefan Ram, Feb 23, 2014
    #15
  16. I *knew* it was wrong. What I didn't know what that stackoverflow was so unreliable (I have had good luck until now)

    Thanks very much for all the advice.

    Jerry
     
    jerry.jeremiah, Feb 23, 2014
    #16
  17. jerry.jeremiah

    Daniel Guest

    Speaking as someone with a stackoverflow reputation of 81,234, so some votes must have hit the target :)

    Daniel
     
    Daniel, Feb 24, 2014
    #17
  18. jerry.jeremiah

    Stuart Guest

    I took your advice and I stumbled upon this posting,
    <ldcp5b$ct9$>, where the poster said that newsgroups
    needed somehow be improved by some rating system in order to sort out
    irrelevant or rather uninteresting postings.

    I don't think that this is necessary. If you follow the newsgroup for a
    while, you get to know people. Whenever I see either Alf, Bart, Bo, Ian,
    James Kanze, Jorgen, Joshua Cramner, Juha, Paavo, Öö, yourself, Tobias
    Müller, Ulrich, or Victor (in alphabetical order), I know that this
    posting is worth reading.

    Brian, Quall, and even Mr. Flibble make some interesting contributions,
    although these are often buried in a mass of off-topic ramblings.

    Regards,
    Stuart
     
    Stuart, Feb 24, 2014
    #18
  19. Well, it is not clear in your
    descriptions of the stack model
    of atuto variables and objs in C++.

    Anyway, the objs in derived classes used by compiled codes to perform
    assignment and copying operations
    in C++ are really tricky in the syntax.
     
    88888 Dihedral, Mar 9, 2014
    #19
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.