//: C07:Stlshape.cpp
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
// Simple tvary using the STL.
#include <vector>
#include <iostream>
using namespace std;

class Tvar {
public:
  virtual void vykresli() = 0;
  virtual ~Tvar() {};
};

class Kruh : public Tvar {
public:
  void vykresli() { cout << "Kruh::vykresli" << endl; }
  ~Kruh() { cout << "~Kruh" << endl; }
};

class Trojuhelnik : public Tvar {
public:
  void vykresli() { cout << "Trojuhelnik::vykresli" << endl; }
  ~Trojuhelnik() { cout << "~Trojuhelnik" << endl; }
};

class Ctverec : public Tvar {
public:
  void vykresli() { cout << "Ctverec::vykresli" << endl; }
  ~Ctverec() { cout << "~Ctverec" << endl; }
};

int main() {
  typedef std::vector<Tvar*> Kontejner;
  typedef Kontejner::iterator Iter;
  Kontejner tvary;
  tvary.push_back(new Kruh);
  tvary.push_back(new Ctverec);
  tvary.push_back(new Trojuhelnik);
  for(Iter i = tvary.begin(); i != tvary.end(); i++)
    (*i)->vykresli();
  // ... někdy později:
  for(Iter j = tvary.begin(); j != tvary.end(); j++)
    delete *j;
} ///:~
