// string.h - header file for class String // (from Learning C++: A Hands on Approach, by Eric Nagler) // entered/tested by cmc, 8/12/03 - reorganized 10/30/13 #ifndef STRING_H #define STRING_H #include // for operator<< // abstraction for a character string - to illustrate C++ class issues class String { public: // friends friend String const join(String const &left, String const &right); friend void display(String const &); // non-member operator function friends: friend String const operator+ // binary plus (concatenates) (String const &left, String const &right); friend std::ostream &operator<< // insertion (to an ostream) (std::ostream &, String const &); // ctors and dtor String(char const * = ""); // both a default and converting ctor String(char); // a converting ctor String(String const &); // copy ctor ~String(); // dtor // features bool search(String const &) const; static unsigned getCount(); // called getInstanceCounter in Nagler String toUpper() const; String &refresh(char const *chars); // member operator functions: String &operator= (String const &); // assignment int operator()(char const *chars = "+") const; // function call // meaning: count occurrences of argument in this String char &operator[] (unsigned) throw(char const *); // subscript-mutable char operator[] (unsigned) const throw(char const *); // subscript-constant String &operator+= (String const &); // compound assignment: += String &operator++ (); // increment - prefix // meaning: increment value of each character in this String String const operator++ (int); // increment - postfix private: char *ptrChars; static unsigned count; }; #endif