Topic: Explicit constructor call within constructor
Author: zeisel@vai.co.at (Helmut Zeisel)
Date: 1996/09/17 Raw View
Is it standard behavior that explicitely calling A() is different from A::A()
when used in A(int)?
In particular, on our compilers under VMS and Solaris,
A() explictely called in A(int) behaves as in ARM 12.1, p. 267
(i.e., it creates a temporary variable).
A::A(), however, creates again the current object without calling the
destructor for the base class.
In particular, the output for the below program is
Base Base ~Base
i.e., one destructor call is missing.
Is this really the standard?
Newsfeed unreliable - please answer also vie e-mail
Helmut Zeisel
Example program:
----------------
#include <iostream.h>
class Base
{
public:
Base()
{
cout << "Base ";
// cout << (void*)(this) << endl; // to get more info
}
~Base()
{
cout << "~Base ";
// cout << (void*)(this) << endl; // to get more info
}
};
class A: public Base
{
public:
A(){}
A(int)
{
// cout << (void*)(this) << endl; // to get more info
A::A();
// A(); does as expected: output "Base Base ~Base ~Base"
}
};
int main()
{
A a(1);
return 1;
}
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]