Vector Iterator Trouble

This code tells me that there is no member variable named _number. I have tried using an -> but that doesn't work either.

#include<vector>
#include<iostream>
using namespace std;

class item
{
public:
int _number;

item( int num )
{
_number = num;
}
};

int main()
{
item* first_item = new item( 5 );

vector< item* > items;
items.push_back( first_item );

vector< item* >::iterator it = items.begin();

while( it != items.end() )
{
cout << *it._number << endl;
++it;
}
return 0;
}

Last edited on
operator precedence problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<vector>
#include<iostream>
using namespace std;
class item{
public:
        int _number;
        item( int num )
        {
               _number = num;
        }
};

int main(){
        item* first_item = new item( 5 );
        vector< item* > items;
        items.push_back( first_item );
        vector< item* >::iterator it = items.begin();

        while( it != items.end() )
        {
                cout << (*it)->_number << endl;
                it++;
        }
    return 0;
}
thank you very much!
Topic archived. No new replies allowed.