iterators

Hii all

I have a vector of class objects. The class has some private data and public function. Can I access the class members with the help of the iterators. I have been trying to do this and been able to access the member function with itr->functionname but have not found anything on accessing the data.

Thanks.
1
2
3
4
5
6
struct foo { void f() {} };

std::vector<foo> v(1);
std::vector<foo>::iterator it = v.begin();
v->f();
well I could do *itr but that wont give me individual class members. and i need to get the class's private data individually. :)
Hi R0mai

Thanks for the promp reply. Didnt really expect it that quick :)

I understand what you are saying. But how can i access the data members of the class with the iterators. Can you help me with that?
You can't access private members with or without an iterator.
In order to access the data, consider adding a 'get' method. For example:
1
2
3
4
5
6
7
class A
{
    int asdf;
public:
    int get_asdf() { return asdf; } const
};
//... 
Topic archived. No new replies allowed.