class encapsulating reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Goche

    #1

    class encapsulating reference

    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.



    Comments appreciated,

    Thanks,

    JG

  • dasjotre

    #2
    Re: class encapsulating reference


    John Goche wrote:
    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.
    >

    >
    Comments appreciated,
    >
    Thanks,
    >
    JG
    from boost::ref documentation:

    "The purpose of boost::referenc e_wrapper<Tis 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."

    Comment

    • John Goche

      #3
      Re: class encapsulating reference

      dasjotre wrote:
      John Goche wrote:
      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.



      Comments appreciated,

      Thanks,

      JG
      >
      from boost::ref documentation:
      >
      "The purpose of boost::referenc e_wrapper<Tis 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



      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

      Comment

      Working...