#ifndef _AMOEBA_H_ #define _AMOEBA_H_ #include #include // This class is useful when you are exploring the behavior of STL // containers. Each instance represents a single Amoeba organism (who // has a name, like 'Charles'!). // // Copy-constructed Amoebas are considered "children" of the Amoeba they were // copied from, and so inherit their parent's name. The class keeps track of how // many generations down the name has been inherited from. // // Assignment operators act as adoption; the left amoeba already was born, but // now takes on the name and generation+1 of its parent, just as a biological // child would have. That said, the adopted amoeba does remember its previous // life, and thus the class keeps track of its former name as well. // // Each of these methods prints out a statement to their effect to stdout, // so we can see how the internals of C++'s STL are actually managing objects // by value class Amoeba { public: ~Amoeba(); Amoeba(); Amoeba(const char *name); Amoeba(const Amoeba &parent); Amoeba &operator=(const Amoeba &other); bool operator<(const Amoeba &other) const; friend std::ostream &operator<<(std::ostream &out, const Amoeba &critter); private: std::string FullName(void) const; std::string name_; // name of this Amoeba std::string formerly_; // previous names of this Amoeba, if adopted int generation_; // how many generations back the name goes }; #endif // _AMOEBA_H_