STL newbie: calling member functions through lists
Hi,
Iam trying to teach myself STL list containers, i haven't been able to figure out how to call a member function for individual objects in a list, I have a list consisting of objects.
heres the code:
Code:
#include<iostream>
#include<list>
using namespace std;
class test
{
int num;
public:
test() {}
test(int a) { num = a; }
int getnum() { return num;}
};
int main()
{
list<test> tlist;
list<test>::iterator titerator;
tlist.push_back(99);
int i = *titerator.getnum(); //wont compile
return 0;
}
Vectors are a lot simpler, i just use the index and dot operator :) I have looked quite a few online tutorials, but haven't found one dealing with a situation like this.
Suppose i remove an element from a vector (say myvec[10]), now would myvec[10] be empty(NULL)??? or do elements shift up to fill in the empty space?
help!
Re: STL newbie: calling member functions through lists
Code:
int main()
{
list<test> tlist;
tlist.push_back(99);
list<test>::iterator titerator = tlist.begin(); // don't let it unitialized!
int i = (*titerator).getnum(); // this does compile.
int j = titerator->getnum(); // this compile also
return 0;
}
Re: STL newbie: calling member functions through lists