rb@cc.ic.ac.uk (Robin Becker) (02/16/91)
Thanks to those people who emailed me concerning this and pointed out
that one of the whoami functions was commented out. I took the source
directly from the net and as far as I can remember made no changes. I
uncommented the whoami and retried; originally I was concerned that
the two compilers gave such different results. They still do and I think
that Zortech is wrong.
extern "C"
{
#include <stdio.h>
}
class base
{
public:
virtual void whatami() { printf("I'm a base.\n"); }
base() { printf("In the base constructor "); whatami(); }
~base() { printf("In the base destructor "); whatami(); }
};
class derived : public base
{
public:
// this one was commented out
virtual void whatami() { printf("I'm a derived.\n"); }
derived() { printf("In the derived constructor "); whatami(); }
~derived() { printf("In the derived destructor "); whatami(); }
};
class mostderived : public derived
{
public:
virtual void whatami() { printf("I'm a mostderived.\n"); }
mostderived() { printf("In the mostderived constructor "); whatami(); }
~mostderived() { printf("In the mostderived destructor "); whatami(); }
};
main()
{
mostderived object;
return 0;
}
should print according to the poster:
In the base constructor I'm a base.
In the derived constructor I'm a derived.
In the mostderived constructor I'm a mostderived.
In the mostderived destructor I'm a mostderived.
In the derived destructor I'm a derived.
In the base destructor I'm a base.
If it doesn't -- call your compiler vendor and complain.
Zortech (compiled with ztc -g test.cpp)
In the base constructor I'm a base.
In the derived constructor I'm a derived.
In the mostderived constructor I'm a mostderived.
In the mostderived destructor I'm a mostderived.
In the derived destructor I'm a mostderived.
In the base destructor I'm a mostderived.
TC++ (Academic version only using default settings)
In the base constructor I'm a base.
In the derived constructor I'm a derived.
In the mostderived constructor I'm a mostderived.
In the mostderived destructor I'm a mostderived.
In the derived destructor I'm a derived.
In the base destructor I'm a base.
seems like ztc is doing something weird!Robin.Becker@stjhmc.fidonet.org (Robin Becker) (02/24/91)
--
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!Robin.Becker
Internet: Robin.Becker@stjhmc.fidonet.org