473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why do i have to assign this iterator pointer to a variable before i can use it?

im using g++ on ubuntu 10.10

i have a pointer to a vector of pointers to objects and i want to call a method on each of those objects.
oc->features is defined as:

vector<Feature*>* features;

i have to do:

Expand|Select|Wrap|Line Numbers
  1. vector<Feature*>::iterator it;
  2.     for (it=oc->features->begin();it!=oc->features->end();it++){
  3.  
  4.         Feature* a=*(it);
  5.         int score=a->scoreFeature(view);
  6. }
  7.  
this works, but if i try to use the itterator directly, as in:

Expand|Select|Wrap|Line Numbers
  1.         int score=*(it)->scoreFeature(view);
  2.  
I get the following compile error:

ViewEvaluator.cpp:48: error: request for member ‘scoreFeature’ in ‘* it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = Feature**, _Container = std::vector<Feature*, std::allocator<Feature*> >]()’, which is of non-class type ‘Feature*’
//make[2]: *** [CMakeFiles/testOVAS.dir/ViewEvaluator.cpp.o] Error 1
//make[1]: *** [CMakeFiles/testOVAS.dir/all] Error 2

non-class type Feature* ?? i dont get it...

can anyone shed light on what might be happening here?

incidentally i thought it could be something to do with having a pointer to a container and using an itterator on it (at first i tried dereferencing that didnt work). I then realised that i have another example in my code using a pointer to vector and the analogous code works.
Feb 8 '11 #1

✓ answered by Banfa

Try this

Expand|Select|Wrap|Line Numbers
  1. int score = (*it)->scoreFeature(view);
  2.  
to override the default operator precedence so that it is dereferenced with * before being deferenced with ->

2 1942
Banfa
9,065 Expert Mod 8TB
Try this

Expand|Select|Wrap|Line Numbers
  1. int score = (*it)->scoreFeature(view);
  2.  
to override the default operator precedence so that it is dereferenced with * before being deferenced with ->
Feb 9 '11 #2
:D thanks Banfa!

it was one of those bugs where i just could see the obvious!
Feb 9 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mike | last post by:
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z...
2
by: lou zion | last post by:
hi all, i've got a class that takes a parameterless function pointer as a parameter. i want to store that function pointer in a variable and i'm trying to figure out the syntax. i came up with...
18
by: ineedyourluvin1 | last post by:
Hi, I would appreciate if someone could tell me what I'm doing wrong ? #include<iostream> using namepace std ; struct person{ char *firstname ; int age ;
3
by: Sunil Korah | last post by:
I dont know whether this is a stupid question. But does access have something akin to the pointer variable in C - or for that matter the '&' operator in xbase. I will explain my reason for...
3
by: Nmishra | last post by:
Hi, I have a problem in assigning a name to a pointer dynamically from another pointer. e.g. if I have char* name = "myPtr"; and I want to have a int pointer having the name as myPtr...
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
7
by: Xiaoshen Li | last post by:
Dear All, I thought I understood using pointer variables as function parameters. But I failed to understand why it is needed pass-by-reference of a pointer variable. To me, pointer variable...
1
by: Roger Oshaug | last post by:
How would I assign the MAX(value) in a tablecolumn to an Integer variable, or put another way, assign any value from a table record to a variable? I am trying to achieve something like this: ...
3
by: sasimca007 | last post by:
how to assign the perl variable to javascript variable?
9
by: sulekhasweety | last post by:
dear all, can anyone explain the differences between pointer variable and reference variables ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.