Problem p00087 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

#define SAFE_DELETE(x)                                                         \\
  {                                                                            \\
    if (x) {                                                                   \\
      delete x;                                                                \\
      x = NULL;                                                                \\
    }                                                                          \\
  }

struct tCell {
  tCell() : x(0.0), prev(NULL), next(NULL) {}

  double x;
  tCell *prev, *next;
};

class MyArray {
public:
  MyArray() : mSize(0), head(NULL), tail(NULL) {
    head = new tCell;
    tail = new tCell;
    head->next = tail;
    tail->prev = head;
  }
  ~MyArray() {
    for (int i = mSize; i > 0; --i) {
      tCell *it = tail->prev;
      it->prev->next = it->next;
      it->next->prev = it->prev;
      SAFE_DELETE(it);
    }
    mSize = 0;
    SAFE_DELETE(tail);
    SAFE_DELETE(head);
  }

  void push(int x) {
    tCell *it = new tCell;
    it->x = x;
    it->prev = tail->prev;
    it->next = tail;
    it->prev->next = it;
    it->next->prev = it;
    ++mSize;
  }
  double pop() {
    tCell *it = tail->prev;
    double ret = it->x;
    it->prev->next = it->next;
    it->next->prev = it->prev;
    SAFE_DELETE(it);
    --mSize;
    return ret;
  }
  double &ref() { return tail->prev->x; }

private:
  int mSize;
  tCell *head, *tail;
};

int getFigure(string &s) {
  bool minus = false;
  int ret = 0;
  if (s[0] == '-') {
    minus = true;
    s.erase(0, 1);
  }
  while (s[0] >= '0' && s[0] <= '9') {
    ret = ret * 10 + static_cast<int>(s[0] - '0');
    s.erase(0, 1);
  }
  s.erase(0, 1);

  return minus ? -ret : ret;
}

int main() {
  string s;

  while (getline(cin, s)) {
    MyArray *stack = new MyArray();
    while (s.size()) {
      if ((s[0] >= '0' && s[0] <= '9') ||
          (s[0] == '-' && s[1] >= '0' && s[1] <= '9')) {
        stack->push(getFigure(s));
      } else {
        double t = stack->pop();
        switch (s[0]) {
        case '+':
          stack->ref() += t;
          break;
        case '-':
          stack->ref() -= t;
          break;
        case '*':
          stack->ref() *= t;
          break;
        case '/':
          stack->ref() /= t;
          break;
        default:
          break;
        }
        s.erase(0, 2);
      }
    }

    cout << setprecision(6) << setiosflags(ios::fixed);
    cout << stack->ref() << endl;

    delete stack;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

#define SAFE_DELETE(x)                                                         \\
  {                                                                            \\
    if (x) {                                                                   \\
      delete x;                                                                \\
      x = NULL;                                                                \\
    }                                                                          \\
  }

struct tCell {
  tCell() : x(0.0), prev(NULL), next(NULL) {}

  double x;
  tCell *prev, *next;
};

class MyArray {
public:
  MyArray() : mSize(0), head(NULL), tail(NULL) {
    head = new tCell;
    tail = new tCell;
    head->next = tail;
    tail->prev = head;
  }
  ~MyArray() {
    for (int i = mSize; i > 0; --i) {
      tCell *it = tail->prev;
      it->prev->next = it->next;
      it->next->prev = it->prev;
      SAFE_DELETE(it);
    }
    mSize = 0;
    SAFE_DELETE(tail);
    SAFE_DELETE(head);
  }

  void push(int x) {
    tCell *it = new tCell;
    it->x = x;
    it->prev = tail->prev;
    it->next = tail;
    it->prev->next = it;
    it->next->prev = it;
    ++mSize;
  }
  double pop() {
    tCell *it = tail->prev;
    double ret = it->x;
    it->prev->next = it->next;
    it->next->prev = it->prev;
    SAFE_DELETE(it);
    --mSize;
    return ret;
  }
  double &ref() { return tail->prev->x; }

private:
  int mSize;
  tCell *head, *tail;
};

int main() {
  int input;
  string s;

  while (getline(cin, s)) {
    MyArray *stack = new MyArray();
    istringstream is(s);
    while (!is.eof()) {
      is >> s;
      if (s[0] >= '0' && s[0] <= '9') {
        istringstream iss(s);
        iss >> input;
        stack->push(input);
      } else {
        double t = stack->pop();
        switch (s[0]) {
        case '+':
          stack->ref() += t;
          break;
        case '-':
          stack->ref() -= t;
          break;
        case '*':
          stack->ref() *= t;
          break;
        case '/':
          stack->ref() /= t;
          break;
        default:
          break;
        }
      }
    }

    cout << setprecision(6) << setiosflags(ios::fixed);
    cout << stack->ref() << endl;

    delete stack;
  }

  return 0;
}