A
Andreas Sch.
Hello,
I had been quite suprised by the
following little program:
---- cut ----
#include "iostream.h"
class base {
public:
base(){}
virtual ~base(){};
void printType(base * obj);
};
class derived : public base {
public:
virtual void doIt()
{
printType(this);
}
};
void base:rintType(base * obj) {
cout << "type is " << typeid(obj).name() << endl;
cout << dynamic_cast<derived *>(obj) << endl;
}
int main(int argc, char * argv[]) {
derived myObj;
myObj.doIt();
}
---- cut ----
It prints:
type is P4base
0xbfffec00
My expectation was to see "derived" for
the type name.
And even if it is identified as "base"
the RTTI should not be able to dynamic-cast
it to a derived object which it is reported
not to be.
Tested with gcc 3.3 and 3.3.2.
Somebody able to enlighten me?
Greetings,
Andreas
I had been quite suprised by the
following little program:
---- cut ----
#include "iostream.h"
class base {
public:
base(){}
virtual ~base(){};
void printType(base * obj);
};
class derived : public base {
public:
virtual void doIt()
{
printType(this);
}
};
void base:rintType(base * obj) {
cout << "type is " << typeid(obj).name() << endl;
cout << dynamic_cast<derived *>(obj) << endl;
}
int main(int argc, char * argv[]) {
derived myObj;
myObj.doIt();
}
---- cut ----
It prints:
type is P4base
0xbfffec00
My expectation was to see "derived" for
the type name.
And even if it is identified as "base"
the RTTI should not be able to dynamic-cast
it to a derived object which it is reported
not to be.
Tested with gcc 3.3 and 3.3.2.
Somebody able to enlighten me?
Greetings,
Andreas