August 2002
Beginner
1122 pages
22h 1m
English
Assuming you've followed this so far, you might have noticed one loose end. What if we want to pass a string as a value argument to a function? As we have seen, with the current setup bad things will happen since the compiler-generated copy constructor doesn't copy strings correctly. Well, you'll be relieved to learn that this, too, can be fixed. The answer is to implement our own version of the copy constructor. Let's take another look at the header file for our string class, in Figure 8.5.
class string { public: string(); string(const string& Str); string& operator = (const string& Str); ~string(); string(char* p); private: short m_Length; char* m_Data; }; ... |
Read now
Unlock full access