August 2001
Beginner
482 pages
10h 52m
English
As you have seen in previous examples, it is possible for the member data of a class to include objects of another class. C++ programmers say that the outer class contains the inner class. Therefore, an Employee class might contain string objects (for the name of the employee) as well as integers (for the employee's salary), and so forth.
Listing 20.3 is a stripped-down but useful String class.
0: #include <iostream> 1: #include <string.h> 2: 3: class String 4: { 5: public: 6: // constructors 7: String(); 8: String(const char *const); 9: String(const String &); 10: ~String(); 11: 12: // overloaded operators 13: char & operator[](int offset); 14: char operator[](int offset) const; 15: String operator+(const ... |
Read now
Unlock full access