request for member which is of non-class type error

Z

zl2k

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
 
K

Kai-Uwe Bux

zl2k said:
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)-
}

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
 
S

Saeed Amrollahi

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)-

}

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top