*Autor: Wojciech Domski* *Markdown flavoured text. Use any Markdown editor to get preview.* # Przykład shared_ptr i listy. ``` #include #include #include using namespace std; class Owoc{ static int liczba; public: Owoc( int pestki_ = 20) : pestki(pestki_){ ++liczba; id = liczba; cout << "Konstruktor, " << id << endl; } ~Owoc(){ cout << "Destruktor, " << id << endl; } int pestki; int id; }; int Owoc::liczba = 0; void foo(shared_ptr p){ cout << "foo, " << p->pestki << endl; } void foo2(Owoc * p){ cout << "foo2, " << p->pestki << endl; } int main() { shared_ptr o; list > lo; o = make_shared (); o->pestki = 10; foo(o); foo2(o.get()); o.reset(new Owoc); o->pestki = 20; foo(o); foo2(o.get()); for( int i = 1; i < 7; ++i) lo.push_back(make_shared (i * 11111)); for( list >::iterator it = lo.begin(); it != lo.end(); ++it) cout << "ID, " << (**it).id << ", Pestki, " << (*it)->pestki << endl; if(lo.size() > 0) lo.pop_back(); lo.push_back(make_shared (88888)); return 0; } ```