This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ destructor not called?


Hi,

The destructor is not called on a1. Is this normal?

# c++ x.cc 
# a.out
global: Inside class A constructor
local: Inside class A constructor
global: Inside class A destructor

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
---
#include <iostream>
#include <stdlib.h>

class A
{
  const char *p;
public:
  A(const char *s) : p (s) { cout << p << ": Inside class A constructor" << endl; }
 ~A() { cout << p << ": Inside class A destructor" << endl; }
};

A a2 ("global");

int main()
{
  A a1 ("local");

  exit (0);
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]