Let's imagine we have two classes.
class Base {}; class Derived : public Base {}; In another part of my code I want to have a variable of type Base which can also hold an object of type Derived.
Base b1, b2; b1 = Base(); b2 = Derived(); In languages like Java or C# this is possible. In c ++, however, I get a slicing error.
Is there a way to replicate the behavior of for example Java in C++?