Dereferencing pointers

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

    Dereferencing pointers

    Is

    *(pointer1->pointer2)

    The same as

    (*(*pointer1).p ointer2)

    TYIA

    nifsmith
  • John Harrison

    #2
    Re: Dereferencing pointers


    "nifsmith" <hawklord451@ly cos.co.uk> wrote in message
    news:cl2lif$5lc $1@sparta.btint ernet.com...[color=blue]
    > Is
    >
    > *(pointer1->pointer2)
    >
    > The same as
    >
    > (*(*pointer1).p ointer2)
    >
    > TYIA
    >
    > nifsmith[/color]

    Yes.

    john


    Comment

    • Sharad Kala

      #3
      Re: Dereferencing pointers


      "nifsmith" <hawklord451@ly cos.co.uk> wrote in message[color=blue]
      > Is
      >
      > *(pointer1->pointer2)
      >
      > The same as
      >
      > (*(*pointer1).p ointer2)
      >[/color]

      Yes.
      Section 5.2.5 paragraph 3 - "If E1 has the type ``pointer to class X,'' then
      the expression E1->E2 is converted to the equivalent form (*(E1)).E2;"

      Sharad


      Comment

      • JKop

        #4
        Re: Dereferencing pointers

        nifsmith posted:
        [color=blue]
        > Is
        >
        > *(pointer1->pointer2)
        >
        > The same as
        >
        > (*(*pointer1).p ointer2)
        >
        > TYIA
        >
        > nifsmith[/color]


        Yes, it is for *pointers*.


        Note however, that for acutal objects, it doesn't always hold true.


        For instance:


        struct Monkey
        {
        int* tail;
        };


        class Blah
        {
        public:

        Monkey a;

        Monkey b;

        Monkey& operator*()
        {
        return a;
        }

        Monkey& operator->()
        {
        return b;
        }
        };


        int main()
        {
        Blah poo;

        int k;

        *( poo->tai l) = &k;

        *( (*poo).tail ) = &k;
        }


        In that above, the statements do two totally different things, ie. there's
        two different "tail"s!

        (Actually now as I'm writing this, I'm not 100% sure that you can overload
        ->)


        -JKop

        Comment

        • Catalin Pitis

          #5
          Re: Dereferencing pointers


          "JKop" <NULL@NULL.NULL > wrote in message
          news:X35dd.3946 9$Z14.13988@new s.indigo.ie...
          [...][color=blue]
          > (Actually now as I'm writing this, I'm not 100% sure that you can overload
          > ->)[/color]

          Yes you can

          Catalin


          Comment

          • JKop

            #6
            Re: Dereferencing pointers

            Catalin Pitis posted:
            [color=blue]
            >
            > "JKop" <NULL@NULL.NULL > wrote in message
            > news:X35dd.3946 9$Z14.13988@new s.indigo.ie...
            > [...][color=green]
            >> (Actually now as I'm writing this, I'm not 100% sure that you can
            >> overload ->)[/color]
            >
            > Yes you can
            >
            > Catalin[/color]



            This pleases me!

            ( C++, 1 point, Bullshit, 0 points )


            -JKop

            Comment

            Working...