#include <stdio.h>
class Base
{
public:
Base()
{
printf("Base()\n");
}
~Base()
{
printf("~Base()\n");
}
};
class Derived:public Base
{
public:
Derived()
{
printf("Derived()\n");
}
void myConst() const
{
printf("Derived's myConst function x=%d",x);
}
~Derived()
{
printf("~Derived()\n");
}
int x;
};
main()
{
Derived *dptr;
dptr=(Derived *)new Base();
dptr->x=10;
dptr->myConst();
delete dptr;
}
In the above code "dptr->myConst()" succeeds without giving any error
on Solaris, but generates an exception when ran on Winodws after
compiling in VC++
My Question is Why does it not fail? since typecasting should not
define x... this call should fail. I replaced "x" with "x[1024]" and
then used the last element in the array above, to isolate the
possiblity of having a fluke. But it still worked !
Thanks.