"laniik" <la****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi. If i have
Class Object {
}
void foo(Object* o)
{
}
void bar(Object& o)
{
}
int main()
{
Object o;
foo(&o);
bar(o);
return 0;
}
I know that in foo, the contents of o are not copied as main just
passes a pointer to the function foo, but my question is, in bar, is
the object o copied? or is just a reference to it passed to the
function? thanks!
The function bar(...) doesn't use a copy either. But there is more happening
here than meets the eye.
The Object& o parameter in bar(...) can't be unbound, not true for a
pointer. This does not mean you can't change the reference's contents. The
reference can't be un-initialized. Hence, in certain cases, a reference can
even extend the lifetime of an object (that doesn't apply here).