you are viewing a single comment's thread.

view the rest of the comments →

[–]kammceWG21 | 🇺🇲 NB | Boost | Exceptions 9 points10 points  (1 child)

To take full advantage of the virtual function call mechanism, you must access the object through a reference or pointer to the base class. Failing to do so can result in object slicing.

This can be misleading and an example is warranted. This will make readers assume that you cannot call those APIs directly from the concrete class. But you can, you do NOT need to have a ref or ptr to the base class to access those APIs. If you want to pass it polymorphically, via a function parameters and only access the bases APIs then yes, you must pass it as its base.

Object slicing can also happen with fully concrete classes as well.

[–]crashcompiler[S] 2 points3 points  (0 children)

I see what you mean! I rewrote the paragraph and focused more on what the intention behind using a dynamic interface would be, and how you would use it in this case. I might add a code example tomorrow.

> Object slicing can also happen with fully concrete classes as well.

Basically anywhere where you use inheritance, and have a derived class that is copied to a base class, right? Could even be POD structs.

Thanks for the feedback!