/* g++ -g stl_test3.cpp -o stl_test3 -static-libstdc++ */ #include <iostream> #include <list> // list 利用のため using namespace std; class PERSON { public: int age; int sex; int life; PERSON(int _age, int _sex) { age = _age; sex = _sex; life = 1; } void func(void){ age += 1; } }; int sub_func(list<PERSON>::iterator pos) { cout << pos->age << " " << pos->sex << " " << pos->life << "\n"; return 0; } int main(){ list<PERSON> person_list; PERSON *person1 = new PERSON(18, 0); PERSON *person2 = new PERSON(23, 1); PERSON *person3 = new PERSON(101, 1); PERSON *person4 = new PERSON(1, 1); person_list.push_back(*person1); person_list.push_back(*person2); person_list.push_back(*person3); person_list.push_back(*person4); cout << "step2" << "\n"; list<PERSON>::iterator pos; for(pos = person_list.begin(); pos!=person_list.end(); ++pos){ cout << pos->age << " " << pos->sex << " " << pos->life << "\n"; sub_func(pos); } return(0); }