request for member which is of non-class type error

Discussion in 'C++' started by zl2k, Sep 12, 2010.

  1. zl2k

    zl2k Guest

    hi, there,

    I got the "request for member which is of non-class type error" for
    the following piece of code:

    for (vector<obj*>::iterator it = objVec.begin(); it < objVec.end(); +
    +it){
    *it->Function(); //the code will be fine if changed to (*it)-
    >Function();

    }

    What does the error message mean? What's the difference between *it->
    and (*it)->? Thanks and have a good weekend.

    zl2k
    zl2k, Sep 12, 2010
    #1
    1. Advertising

  2. zl2k

    Kai-Uwe Bux Guest

    zl2k wrote:

    > hi, there,
    >
    > I got the "request for member which is of non-class type error" for
    > the following piece of code:
    >
    > for (vector<obj*>::iterator it = objVec.begin(); it < objVec.end(); +
    > +it){
    > *it->Function(); //the code will be fine if changed to (*it)-
    >>Function();

    > }
    >
    > What does the error message mean? What's the difference between *it->
    > and (*it)->? Thanks and have a good weekend.


    *it->Function() is *((*it).Function())
    (*it)->Function() is (*(*it)).Function()

    In the first line, you have the subexpression

    (*it).Funciton()

    but *it is of type obj*, i.e., it's not a type that has a member function
    called "Function".


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Sep 12, 2010
    #2
    1. Advertising

  3. On Sep 12, 6:44 pm, zl2k <> wrote:
    > hi, there,
    >
    > I got the "request for member which is of non-class type error" for
    > the following piece of code:
    >
    > for (vector<obj*>::iterator it = objVec.begin(); it < objVec.end(); +
    > +it){
    >     *it->Function(); //the code will be fine if changed to (*it)-
    >
    > >Function();

    > }
    >
    > What does the error message mean? What's the difference between *it->
    > and (*it)->? Thanks and have a good weekend.
    >
    > zl2k


    Hi
    Besides what Kai-Uwe wrote, the problem is
    about priority of operators. Please note, the priority of
    '->' is very high. If you see the operator summary table in a
    typical C/C++ book like The C++ Programming Language
    or The C Programming Language, or C++ Primer, it is on the top
    of the table and * (indirection operator) in the middle.
    On the other hand you have a vector of pointers to
    objects. So you have to put () around of * operator
    to change the priority.

    Regards,
    -- Saeed Amrollahi
    Saeed Amrollahi, Sep 13, 2010
    #3
    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. E11
    Replies:
    1
    Views:
    4,711
    Thomas Weidenfeller
    Oct 12, 2005
  2. ghager
    Replies:
    6
    Views:
    612
    ghager
    Jan 19, 2006
  3. Andre
    Replies:
    4
    Views:
    12,616
    Kai-Uwe Bux
    Nov 18, 2007
  4. ztycho
    Replies:
    1
    Views:
    1,048
    joseph cook
    Aug 11, 2008
  5. AJ
    Replies:
    6
    Views:
    1,382
    Joe Greer
    Dec 4, 2009
Loading...

Share This Page