Will the Destructor Be Called?

| Comments

Here’s a C++ quiz for all of you: somefunc() will be called from a thread. Do you think this destructor will be called?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class A {
public:
  A () {
      printf("Constructor\t");
  }

  ~A() {
      printf("Destructor\n");
  }
};

int somefunc () {
  A inst;
  int* a = 0
  *a = 1;
  return 0;
}

Comments