Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » |SOLVED] Vector of object: cast to inherited class
Re: |SOLVED] Vector of object: cast to inherited class [message #52384 is a reply to message #52383] Mon, 16 September 2019 17:44 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Xemuth wrote on Mon, 16 September 2019 10:47
Novo wrote on Mon, 16 September 2019 16:31
Xemuth wrote on Mon, 16 September 2019 03:35

Quote:
Why the code below is working the way it is working (printing out "Hello from A" instead of "Hello from B")?


That's because we didn't define any destructor on B.

This is not a correct answer.


Since B inherite from A, B will call A's destructor right after exection of is own destructor.

This particular statement is correct, but Hello() is a virtual method and it is supposed to print "Hello from B".

B b;
A* a = &b;
a->Hello();

This code will print "Hello from B".
Why the code in quiz is working differently?


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: copying code from web into IDE
Next Topic: Simple way to develope 2D Game
Goto Forum:
  


Current Time: Mon Apr 29 05:02:38 CEST 2024

Total time taken to generate the page: 0.02660 seconds