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
Зворотній Зв’язок
Зареєструйся Зараз
або Підпишись на майбутні тести