ordering of constructors
Chris Lattner
sabre@nondot.org
Fri Apr 9 17:53:00 GMT 2004
> So in this case, the output should be:
> main()
> ~B()
> ~A()
No, I don't think it should be. Consider this modified program, which
just prints out the order of construction as well:
------------
#include <stdio.h>
struct A {
A() { printf("A()\n"); }
~A() { printf("~A()\n"); }
};
A &a() {
static A value;
return value;
}
struct B {
B() { printf("B()\n"); a(); }
~B() { printf("~B()\n"); }
};
B b;
int main() {
printf("main()\n");
return 0;
}
--------------
This prints:
B()
A()
main()
~A()
~B()
... which is what I would expect. The order of destruction has to be the
opposite of the order of construction.
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
More information about the Gcc
mailing list