Suppose a String class has the following private members: class String { private: char * str; //

Question:

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);
}


Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

C++ Primer Plus

ISBN: 9780321776402

6th Edition

Authors: Stephen Prata

Question Posted: