This code calls another ctor in one ctor:
#include <iostream> using namespace std; class F { public: F() { cout << "ctor1\n"; } F(int) { cout << "ctor2\n"; } ~F() { cout << "dtor\n"; } }; class Foo { F f; public: Foo() : f() { cout << "1\n"; } Foo(int i) : f(i) { Foo(); cout << "2\n"; } }; int main() { Foo object(1); return 0; }
Result:
ctor2 ctor1 1 dtor 2 dtor
It seems that the member variable f destroyed here twice, is this normal?
source share