Re: What's the point of passing parameter by value (vs. const ref)
On Jul 7, 6:36 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
On Wed, 2 Jul 2008 11:58:01 CST, Martin T. <0xCDCDC...@gmx.at> wrote:
void f_ref_int(const int& x) {
int y = x;
y++;
}
The number one reason against pass-by-const-reference here is not
technical: it looks funny, it is (I think it's safe to say) at best
pointless, and nobody else is doing it.
Would you make this statement if 'int' were replaced with 'Foo', where
Foo is a class or struct?
The way I react when I read someone's code and it contains odd
constructs which don't actually /do/ anything, is that I start to
distrust the rest of the code, too. Clearly, that hurts both me and
the author.
Sometimes, sticking to tradition is the best way.
I just did a grep for such constructs in my pet project: 1726
occurences in 535 files.
What it does for me is let caller pass aggregates by computationally-
less-expensive reference with a contract that callee will be unable to
modified object being referred to. :)
How do you pass aggregates?
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]