Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
typeid and dynamic_cast, gcc 3.3
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Andreas Sch., post: 1478056"] 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::printType(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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
typeid and dynamic_cast, gcc 3.3
Top