passing references

C

conrad

In C, we have pass by value only.
This results from values being the
product of 'the value of the expression'.

Now, I imagine that the C++ standard
has the same concept of the
'value of the expression' but I wonder
what it yields in such a case when
passing a reference to a function
that expects a reference. Would it
perhaps be 'an object of the expression'?
 
V

Victor Bazarov

conrad said:
In C, we have pass by value only.
This results from values being the
product of 'the value of the expression'.

Now, I imagine that the C++ standard
has the same concept of the
'value of the expression' but I wonder
what it yields in such a case when
passing a reference to a function
that expects a reference. Would it
perhaps be 'an object of the expression'?

Yes. If the result of the expression is an object, then
a reference can be bound to it and the reference argument
can be initialised from the object. To boot, there is
a way to create an object (from some expression result)
and pass it into a function that expects a reference to
a constant object. The language allows (or prescribes)
that in such a case a _temporary_ object will be created
and the reference will be bound to it.

V
 
V

vijay

Yes. If the result of the expression is an object, then
a reference can be bound to it and the reference argument
can be initialised from the object. To boot, there is
a way to create an object (from some expression result)
and pass it into a function that expects a reference to
a constant object. The language allows (or prescribes)
that in such a case a _temporary_ object will be created
and the reference will be bound to it.

V


awesome reply victor !!
 

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

Forum statistics

Threads
474,201
Messages
2,571,051
Members
47,656
Latest member
rickwatson

Latest Threads

Top