[Quiz]


Find a bug why run time error occurs.




[Source]


#include <iostream>
#include <string>

using namespace std;

#define SAFE_DELETE(A) { if(A != NULL) { delete (A); A = NULL; } }

class MyString
{
public:
  string* m_str;
  MyString()              { m_str = NULL; }
  MyString(const char* p) { m_str = new string(p); }
  virtual ~MyString()     { SAFE_DELETE(m_str); }
};

void write(MyString s)
{
  if (s.m_str != NULL)
    cout << *s.m_str << endl;
}

int main()
{
  MyString s = "test";
  write(s);
  return 0;
}




[Download]


test.zip