-bat.
#include <stdlib.h>
#include <iostream.h>
class super_ex {
public :
super_ex(void);
virtual ~super_ex(void);
};
class sub_ex : public super_ex {
public :
sub_ex(void);
virtual ~sub_ex(void);
};
super_ex::super_ex(void)
{
cout << "Superclass constructor\n";
}
super_ex::~super_ex(void)
{
cout << "Superclass destructor\n";
}
sub_ex::sub_ex(void)
{
// cout << "Subclass constructor\n";
}
sub_ex::~sub_ex(void)
{
cout << "Subclass destructor\n";
}
int
main(void)
{
super_ex *f = new sub_ex;
cout << "Created class\n";
delete f;
}
> Does anybody know why the following code does not work under cc++
> on OpenStep 4.2 and if there is a workaround at all ? It works fine
> on other C++ compilers. If you uncomment the line in the subclass constructor
> it works fine under OpenStep. Any ideas ?
>
This looks like the one I reported about three years ago in the 4.0 beta
release (when I ported Animo to OpenStep). If you have a subclass with an
(almost) empty contructor, then the compiler forgets to set up the virtual
function dispatch table.
It seems to work properly if you turn on optimisation!
$an
I'm not convinced it's entirely a compiler problem though - I have
a script called 'cc3' which does 3.3 compilation under 4.2 usingall
the old headers and libraries, *but* it still uses the 4.2 compiler
to do the actual compilation. Using cc3 the code works fine, using cc it
fails.
> It seems to work properly if you turn on optimisation! > >
This is true...
Anyway, I re-wrote the whole lot in C instead - which I shiuld probably
have done anyway, I just thought C++ was an easy way to convert a load of
Objective C so the plebs on M$ could use it. Silly idea, should have known
better really. Thanks for all the advice though...
-bat.