Here is some test code:
#include <iostream>
#include <forward_list>
using namespace std;
class whoKnows
{
private:
int hidden;
public:
int getHidden();
void setHidden(int newint);
};
int whoKnows::getHidden()
{
return hidden;
}
void whoKnows::setHidden(int newint)
{
hidden = newint;
}
int main()
{
forward_list<whoKnows> test;
whoKnows unknown;
whoKnows twelve;
twelve.setHidden(12);
whoKnows thirty;
thirty.setHidden(30);
whoKnows six;
six.setHidden(6);
test.push_front(twelve);
test.push_front(thirty);
test.push_front(six);
cerr<<"Showing all values.\n";
for(auto it = test.begin(); it != test.end(); it++)
{
unknown = *it;
cerr<<"Class found, value: "<<unknown.getHidden()<<"\n";
}
cerr<<"Increasing all values.\n";
for(auto it = test.begin(); it != test.end(); it++)
{
unknown = *it;
unknown.setHidden(unknown.getHidden()+1);
}
cerr<<"Reshowing all values.\n";
for(auto it = test.begin(); it != test.end(); it++)
{
unknown = *it;
cerr<<"Class found, value: "<<unknown.getHidden()<<"\n";
}
cout<<"Done\n";
return 0;
}
Ideally the second iteration of values would all be one more than the first time, but they are not.A forward list would work for me, as I have a program that every frame loops though each object (begin to end) and runs a method which will modify values in that class. As long as I can remove an object at any point in the container, I don't need to access elements randomly, only from begining to end.