So I was asked to solve this question...however when i compile it, it doesn't work...could somebody tell me what's wrong and how to solve it (im guessing it's something to do with overloading since my lecturer was talking abt it just before this was given)? thanks a lot!

#include <iostream>
#include <vector>
using namespace std;
class Integer {
        int value;
int main() {
    vector<Integer> v;
    for( int i=0; i<10; i++ ) {
        Integer x;
        x.value = i;
        v.push_back( x );
    vector<Integer>::iterator itr;
    for( itr=v.begin(); itr!=v.end(); itr+=2 )
        cout << *itr << endl;

    return 0;
Re: iterator and overloading 80 80

Line 17: cout << *itr << endl;
*itr is of type Integer, so what you want is the value member of class Integer
cout << static_cast<Integer>(*itr).value << endl;

Re: iterator and overloading 80 80

Now, I'm not a terribly smart man, but on line 17, wouldn't you be trying to print the value property of the Integer that itr points to?
EDIT: Beat me to it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.