I can't understand this "const*&" stands for?

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

    I can't understand this "const*&" stands for?

    void push_front(Node const*& head, int data);


    Can someone tell me what it means for "const*&"? A reference or a pointer?


  • Jakob Bieling

    #2
    Re: I can't understand this "const*&am p;" stands for?

    "hoox2" <xxx@sss.com> wrote in message news:bls38m$c0o 5@rain.i-cable.com...[color=blue]
    > void push_front(Node const*& head, int data);
    >
    >
    > Can someone tell me what it means for "const*&"? A reference or a pointer?[/color]

    Both, sort of *g* Read everything from right to left: 'head' is a
    reference to a pointer to a constant 'Node'. This means the passed pointer
    can be modified by the function, but the object the pointer points to cannot
    be modified.

    hth
    --
    jb

    (replace y with x if you want to reply by e-mail)


    Comment

    • David B. Held

      #3
      Re: I can't understand this &quot;const*&am p;&quot; stands for?

      "hoox2" <xxx@sss.com> wrote in message news:bls38m$c0o 5@rain.i-cable.com...[color=blue]
      > void push_front(Node const*& head, int data);
      >
      >
      > Can someone tell me what it means for "const*&"? A
      > reference or a pointer?[/color]

      Except for an initial const, these kinds of types should be
      understood from left to right:

      Node const x; // a const object of type Node
      Node const* x; // a pointer to a const Node object
      Node const* &x; // a reference to a pointer to a const Node

      My guess is that push_front() is an operation that works
      on lists, which is probably why it takes head by reference.
      Since the function probably doesn't need to modify the
      pointed-to Node object, it takes that as const. Since it
      is probably going to modify the head pointer, it takes
      that as non-const &.

      Dave



      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


      Comment

      • Jonathan Mcdougall

        #4
        Re: I can't understand this &quot;const*&am p;&quot; stands for?

        > void push_front(Node const*& head, int data);[color=blue]
        >
        >
        > Can someone tell me what it means for "const*&"? A reference or a pointer?[/color]

        A const reference to a pointer. The function probably reset your pointer
        to 0, meaning it takes ownership of the object, though the name 'head' makes
        me wonder about that.


        Jonathan


        Comment

        • Howard

          #5
          Re: I can't understand this &quot;const*&am p;&quot; stands for?


          "Jonathan Mcdougall" <jonathanmcdoug all@DELyahoo.ca > wrote in message
          news:vWigb.5001 2$282.685877@we ber.videotron.n et...[color=blue][color=green]
          > > void push_front(Node const*& head, int data);
          > >
          > >
          > > Can someone tell me what it means for "const*&"? A reference or a[/color][/color]
          pointer?[color=blue]
          >
          > A const reference to a pointer. The function probably reset your pointer
          > to 0, meaning it takes ownership of the object, though the name 'head'[/color]
          makes[color=blue]
          > me wonder about that.
          >[/color]

          Nope...it's a reference to a pointer to a constant Node object, not a const
          reference.

          The const keyword could go in front of the Node and it would be the same,
          but otherwise read it from right-to-left to get:
          reference-to-pointer-to-const-Node.

          -Howard

          [color=blue]
          >
          > Jonathan
          >
          >[/color]


          Comment

          • Jonathan Mcdougall

            #6
            Re: I can't understand this &quot;const*&am p;&quot; stands for?

            > > > void push_front(Node const*& head, int data);[color=blue][color=green][color=darkred]
            > > >
            > > >
            > > > Can someone tell me what it means for "const*&"? A reference or a[/color][/color]
            > pointer?[color=green]
            > >
            > > A const reference to a pointer. The function probably reset your[/color][/color]
            pointer[color=blue][color=green]
            > > to 0, meaning it takes ownership of the object, though the name 'head'[/color]
            > makes[color=green]
            > > me wonder about that.
            > >[/color]
            >
            > Nope...it's a reference to a pointer to a constant Node object, not a[/color]
            const[color=blue]
            > reference.
            >
            > The const keyword could go in front of the Node and it would be the same,
            > but otherwise read it from right-to-left to get:
            > reference-to-pointer-to-const-Node.[/color]

            You're right, sorry.


            Jonathan


            Comment

            • hoox2

              #7
              Re: I can't understand this &quot;const*&am p;&quot; stands for?

              Thanks all of you for your valuable and helpful explanation.


              Regards,


              Ho


              Comment

              Working...