Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > request for member which is of non-class type error

Reply
Thread Tools

request for member which is of non-class type error

 
 
zl2k
Guest
Posts: n/a
 
      09-12-2010
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
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      09-12-2010
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
 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      09-13-2010
On Sep 12, 6:44*pm, zl2k <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Error: error: request for member ‘GetX’ in ‘ball’, which is of non-class type ‘Ball ()()’ AJ C++ 6 12-04-2009 01:42 PM
pointer to a member of a struct which is in turn a member of an arrayof structs pete142 C Programming 5 01-23-2008 01:11 AM
error: request for member of non-class type Andre C++ 4 11-18-2007 12:07 PM
What is the correct grammar to make a function call by using static member data which is a pointer to a ordinary class member function? zaeminkr@gmail.com C++ 3 07-06-2007 12:50 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments