implicit passing by reference

J

jerry.jeremiah

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
 
J

Jorgen Grahn

(e-mail address removed) wrote in


In C++ the function declarations specify exactly if the pass is by value
or by reference.

Or you could say it's always by value -- but you can choose to pass a
reference or pointer to some object.
The people at stackoverflow probably have confused C++
with some other language.

Yes, and you have to be pretty confused to do that.
I tell my coworkers to avoid stackoverflow because of stuff like
this.

/Jorgen
 
M

Marcel Müller

Or you could say it's always by value -- but you can choose to pass a
reference or pointer to some object.

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.
Yes, and you have to be pretty confused to do that.
I tell my coworkers to avoid stackoverflow because of stuff like
this.

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
 
8

88888 Dihedral

(e-mail address removed) wrote in












In C++ the function declarations specify exactly if the pass is by value

or by reference. The people at stackoverflow probably have confused C++

with some other language. Do not take stackoverflow too seriously, the

answers there are ranked by the person least qualified to judge the

correctness.



Cheers

Paavo

Well, an object in C++ has some hidden
field to store the address of this object in the C sense.
 
V

Victor Bazarov

[...]
Well, an object in C++ has some hidden
field to store the address of this object in the C sense.

I will probably regret this later, but... What the hell do you mean?

V
 
O

Osmium

Victor Bazarov said:
[...]
Well, an object in C++ has some hidden
field to store the address of this object in the C sense.

I will probably regret this later, but... What the hell do you mean?

Now you did it. You reactivated him after a long dormant period.
 
V

Victor Bazarov

Victor Bazarov said:
[...]
Well, an object in C++ has some hidden
field to store the address of this object in the C sense.

I will probably regret this later, but... What the hell do you mean?

Now you did it. You reactivated him after a long dormant period.

I did? Damn... I thought he was replying to Paavo. Ah, no matter.
Sorry! My fault! I really regret this! Etc. etc.

V
 
R

red floyd

I did? Damn... I thought he was replying to Paavo. Ah, no matter.
Sorry! My fault! I really regret this! Etc. etc.

You are hereby sentenced to 200 hours of listening to Justin Bieber
albums.
 
I

Ian Collins

red said:
You are hereby sentenced to 200 hours of listening to Justin Bieber
albums.

That, being a cruel and inhumane punishment, would be considered a
breach of Victor's human rights by the European court :)
 
V

Victor Bazarov

That, being a cruel and inhumane punishment, would be considered a
breach of Victor's human rights by the European court :)

I still probably deserve it. Besides, I don't reside in the
jurisdiction of the European court :-[

V
 
R

red floyd

That, being a cruel and inhumane punishment, would be considered a
breach of Victor's human rights by the European court :)

I still probably deserve it. Besides, I don't reside in the
jurisdiction of the European court :-[

Just giving you a hard time, Victor. The opportunity was too good
to pass up. :-D
 
J

Jorgen Grahn

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.

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
 
J

James Kanze

Do not take stackoverflow too seriously, the
answers there are ranked by the person least qualified to judge the
correctness.

You've noticed that too. The highest ranked answers are rarely
the correct ones.
 
J

James Kanze

I tell my coworkers to avoid stackoverflow because of stuff like
this.

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.)
 
S

Stefan Ram

James Kanze said:
You've noticed that too. The highest ranked answers are rarely
the correct ones.

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.
 
J

jerry.jeremiah

In C++ the function declarations specify exactly if the pass is by value or by reference. The people at stackoverflow probably have confused C++ with some other language. Do not take stackoverflow too seriously, the answersthere are ranked by the person least qualified to judge the correctness.

Cheers

Paavo

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
 
D

Daniel

The highest ranked answers are rarely the correct ones.
Speaking as someone with a stackoverflow reputation of 81,234, so some votes must have hit the target :)

Daniel
 
S

Stuart

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.

I took your advice and I stumbled upon this posting,
<[email protected]>, 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
 
8

88888 Dihedral

Yes, and you have to be pretty confused to do that.

I tell my coworkers to avoid stackoverflow because of stuff like

this.

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top