Question: Suppose a String class has the following private members: class String { private: char * str; // points to string allocated by new int len;
Suppose a String class has the following private members:
class String
{
private:
char * str; // points to string allocated by new
int len; // holds length of string
//...
};
a. What’s wrong with this default constructor?
String::String() {}
b. What’s wrong with this constructor?
String::String(const char * s)
{
str = s;
len = strlen(s);
}
c. What’s wrong with this constructor?
String::String(const char * s)
{
strcpy(str, s);
len = strlen(s);
}
Step by Step Solution
3.45 Rating (174 Votes )
There are 3 Steps involved in it
a There is no problem with this default constructor but it might do a lot of work for an empt... View full answer
Get step-by-step solutions from verified subject matter experts
