Hi,
Below is my code, i was expecting an error from program because when i print the base pointer before and after assigning derived pointer it is different.
despite holding derived pointer, which does not have the invoking function
the program works , i mean prints "base", how?
should not it print func is not available in derived class?
My question is bptr is pointing to dptr and when we call bptr->func() ( func is actually not available in class derived ) why is it not throwing an error, how come bptr is able to call class base , though it is having class derived address.
The Liskov Substitutability Principle says that an instance of a derived class must be usable anywhere a base class is acceptable. This is one of the basic ideas behind object-oriented programming, part of the so-called SOLID principles. https://en.wikipedia.org/wiki/SOLID
Public inheritance models the is-a relationship:
A derived class is-a (specialization of its) base class.
As such, the derived class inherits all the public and protected data and behavior from the base class.