|
|
 |
|
|
|
|
9: public:
10: // constructors
11: String();
12: String(const char *const);
13: String(const String &);
14: ~String();
15:
16: // overloaded operators
17: char & operator[](int offset);
18: char operator[](int offset) const;
19: String operator+(const String&);
20: void operator+=(const String&);
21: String & operator= (const String &);
22: friend ostream& operator<<( ostream& theStream, String& theString);
23: // General accessors
24: int GetLen()const { return itsLen; }
25: const char * GetString() const { return itsString; }
26: // static int ConstructorCount;
27:
28: private:
29: String (int); // private constructor
30: char * itsString;
31: int itsLen;
32:
33: };
34:
35: // default constructor creates string of 0 bytes
36: String::String()
37: {
38: itsString = new char[1];
39: itsString[0] = \0;
40: itsLen=0;
41: // cout << \tDefault string constructor\n;
42: // ConstructorCount++;
43: }
44:
45: // private (helper) constructor, used only by
46: // class methods for creating a new string of
47: // required size. Null filled.
48: String::String(int len)
49: {
50: itsString = new char[len+1];
51: int i;
52: for ( i = 0; i<=len; i++)
53: itsString[1] = \0;
54: itsLen=len;
55: // cout << \tString(int) constructor\n;
56: // ConstructorCount++;
57: } |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|