class encapsulating reference

D

dasjotre

John said:
Hello,

The class TRefByValue in the Symbian OS API
encapsulates a reference inside a class so that
it can be passed by value to functions. But why
would we want this? After all, if a function needs
to take a reference parameter, why code the
function to take TRefByValue as a value
parameter instead? I don't see any
advantage to this.

http://www.symbian.com/developer/te...ce/reference-cpp/N101CA/TRefByValueClass.html

Comments appreciated,

Thanks,

JG

from boost::ref documentation:

"The purpose of boost::reference_wrapper<T> is to contain
a reference to an object of type T. It is primarily used to
"feed" references to function templates (algorithms)
that take their parameter by value."
 
J

John Goche

dasjotre said:
from boost::ref documentation:

"The purpose of boost::reference_wrapper<T> is to contain
a reference to an object of type T. It is primarily used to
"feed" references to function templates (algorithms)
that take their parameter by value."

Thank you dasjotre for your reply.

However, I do not see the point in the definition of RTest::printf for
example. See

http://www.symbian.com/developer/te...-cpp/N101CA/RTestClass.html#::RTest::Printf()

Here the argument to Printf is not a templated parameter
passed by value as in the boost example you mentioned.
So why is the TDesC string parameter passed in this way?

Furthermore, what is the meaning of

operator &()

as found in TRefByValue? What does this do?

Thanks,

JG
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top