order of calling overloaded operators

Discussion in 'C++' started by ES Kim, May 23, 2006.

  1. ES Kim

    ES Kim Guest

    iterator classes provide overloaded operators like this in general:

    template <typename T>
    class Iterator
    {
    Iterator operator++(int); // postfix ++
    T& operator*();
    };

    Iterator<int> i;
    *i++;

    You know postfix ++ has higher precedence than unary *.
    Does it gaurantee that postfix ++ is called before unary * operator?

    --
    ES Kim
     
    ES Kim, May 23, 2006
    #1
    1. Advertising

  2. ES Kim wrote:
    > iterator classes provide overloaded operators like this in general:
    >
    > template <typename T>
    > class Iterator
    > {
    > Iterator operator++(int); // postfix ++
    > T& operator*();
    > };
    >
    > Iterator<int> i;
    > *i++;
    >
    > You know postfix ++ has higher precedence than unary *.


    It`s the dereferencing operator, not unary * (which does not exist).

    > Does it gaurantee that postfix ++ is called before unary * operator?


    Of course. The point of operator precedence is to guarantee the order
    in which these operators are called.

    *p++ is always *(p++) and a+b*c is always a+(b*c).


    Jonathan
     
    Jonathan Mcdougall, May 23, 2006
    #2
    1. Advertising

  3. ES Kim

    Luke Meyers Guest

    Jonathan Mcdougall wrote:
    > ES Kim wrote:
    > > You know postfix ++ has higher precedence than unary *.

    >
    > It's the dereferencing operator, not unary * (which does not exist).


    Oh, come now. It's a unary operator represented by the symbol '*', and
    you and everybody else knew exactly what the OP meant. In fact,
    §5.3.1 [expr.unary.op] uses the exact term "the unary * operator" to
    refer to this entity. Perhaps you just enjoy bullying, rather than
    helping to inform? If you're going to be pedantic, have the decency to
    be correct.

    Luke
     
    Luke Meyers, May 23, 2006
    #3
  4. Luke Meyers wrote:
    > Jonathan Mcdougall wrote:
    > > ES Kim wrote:
    > > > You know postfix ++ has higher precedence than unary *.

    > >
    > > It's the dereferencing operator, not unary * (which does not exist).

    >
    > Oh, come now. It's a unary operator represented by the symbol '*', and
    > you and everybody else knew exactly what the OP meant. In fact,
    > §5.3.1 [expr.unary.op] uses the exact term "the unary * operator" to
    > refer to this entity.


    It was my intention to remove that line, but I forgot before posting. I
    apologize.

    > Perhaps you just enjoy bullying, rather than
    > helping to inform? If you're going to be pedantic, have the decency to
    > be correct.


    True.


    Jonathan
     
    Jonathan Mcdougall, May 23, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -Steve-
    Replies:
    2
    Views:
    372
    - Steve -
    Jul 28, 2003
  2. John Harrison
    Replies:
    5
    Views:
    329
    - Steve -
    Jul 29, 2003
  3. Andy Jarrell

    Inheriting overloaded operators

    Andy Jarrell, Nov 13, 2003, in forum: C++
    Replies:
    5
    Views:
    440
    Victor Bazarov
    Nov 13, 2003
  4. Pete Wilson
    Replies:
    1
    Views:
    320
    Mike Wahler
    Apr 3, 2004
  5. NKOBAYE027
    Replies:
    2
    Views:
    357
    NKOBAYE027
    May 8, 2004
Loading...

Share This Page