Does this code contain an error (compilation, execution, or undefined behavior)?
struct A {
  int *i;
  A() : i(new int(0)) { }
  ~A() { delete i; }

int main() {
  A a;
  A b = a;
  return 0;
There is a "double delete bug" because b is copied byte by byte from a using the automatically generated copy constructor, after which the destructor ~A() is called twice for the same variable.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Зарегистрируйся сейчас
или Подпишись на будущие тесты