------=_NextPart_000_000C_01BD763E.D0F85EF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
HELP!! Just when I thought I understood C++, I came across this (odd??) =
behavior.
Suppose you have the following class inheritance:
class TTest : public TBase =20
{
public:
TTest();
TTest(const TBase& source);
virtual ~TTest();
};
class TBase =20
{
public:
TBase();
TBase(const TBase& source);
virtual ~TBase();
};
TBase::TBase() { printf("TBase default constructor %p\n", this); }
TBase::TBase(const TBase &source) { printf("TBase copy constructor =
%p\n", this); }
TBase::~TBase() { printf("TBase destructor %p\n", this); }
TTest::TTest() : TBase() { printf("TText default constructor %p\n", =
this); }
TTest::TTest(const TBase& source) { printf("TText(TBase) copy =
constructor %p\n", this); }
TTest::~TTest() { printf("TText destructor %p\n", this);}
int main()
{
TTest test1;
TTest test2 =3D test1;
=20
printf("done\n");
=20
return;
}
// program output
TBase default constructor 0012FF70
TText default constructor 0012FF70
TBase copy constructor 0012FF6C
done
TText destructor 0012FF6C
TBase destructor 0012FF6C
What dont understand is how the various copy constructors are =
implemented. In the below example, the base class of test1 is called =
(why?? I didn't specify it using TTest() : TBase()). Also, for test2, =
the only constructor called is for the TBase. This doesn't seem to make =
sense to me. Is this correct, and if so is there any logic behind it??
William J Deninger
deninger@uiuc.edu
------=_NextPart_000_000C_01BD763E.D0F85EF0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">