I'd recommend you read some tutorials on C++ pointers, arrays, structs, classes, new/delete usage, and stl. There's just so much wrong with that last example you posted, I can't begin to explain it other than saying "go learn C++".
I will, however, give you a solution:
I will, however, give you a solution:
#include "stdafx.h" #include <iostream> #include <list> using namespace std; struct Address { typedef list<Address*> List; typedef list<Address*>::iterator ListIterator; public: Address(); ~Address(); static List classList; int age; private: ListIterator i; }; Address::Address() { classList.push_front(this); i = classList.begin(); } Address::~Address() { classList.erase(i); } int main() { Address martin; Address joe; martin.age = 16; joe.age = 10; // cout << "Age (martin): " << martin.age << "\n"; // cout << "Age (joe): " << joe.age << "\n"; Address::ListIterator i; Address *x; for (i = Address::classList.begin(); i != Address::classList.end(); ++i) { x = *i; cout << x->age << "\n"; } cin.get(); }