Exercises

1.What would happen if we compiled the program in Figure 8.37? Why?
Figure 8.37. Exercise 1 (code\strex5.cpp)
class string
{
public:
  string(const string& Str);
  string(char* p);
  string& operator = (const string& Str);
  ~string();
private:
  string();
  short m_Length;
  char* m_Data;
};

int main()
{
  string n("Test");
  string x = n;

  n = "My name is Susan";

  return 0;
}
2.What would happen if we compiled the program in Figure 8.38? Why?
Figure 8.38. Exercise 2 (code\strex6.cpp)
class string
{
public:
  string();
  string& operator = (const string& Str);
private:
  string(char* p);
  short m_Length;
  char* m_Data;
};

int main()
{
  string n;

  n = "My name is Susan";

  return 0;
}
3.We have already implemented operator < and operator ==. However, a concrete ...

Get C++: A Dialog Programming with the C++ Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.