0
Isn't this code have something special ??
Refer code below and observe the output. It is base class which we get as output for both the pointers Now just uncomment getclassname method from both the class... No need to uncomment the code which calls this method. We are getting now different result. Why so ? https://code.sololearn.com/cHrjT5fPzu8D/?ref=app
2 Antworten
+ 1
Hi Ketan! It happens because in the first case the base class is not polymorphic (class without any virtual member). In second case the class is polymorphic due to the method you just uncommented!
To prove that you can just create a virtual method in base class to turn it polymorphic and run the code again
+ 1
Thanks Victor Cortes ... I just tried with only having deafult virtual destructor in base class nd it worked...
Thanks for your help