Hi,
The Note section of following isocpp guideline,
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c10-prefer-concrete-types-over-class-hierarchies ,
says :
Note The use of indirection is fundamental for run-time polymorphic interfaces. The allocation/deallocation overhead is not (that’s just the most common case). We can use a base class as the interface of a scoped object of a derived class. This is done where dynamic allocation is prohibited (e.g. hard-real-time) and to provide a stable interface to some kinds of plug-ins.
|
I am literally not able to understand what does the above para means in terms of code implementation.
I would really appreciate if someone can help me with a code example on what does above para is trying to convey.
I am specifically looking for explanations to following :
[1] The use of indirection is fundamental for run-time polymorphic interfaces. The allocation/deallocation overhead is not (that’s just the most common case)
==> Does that mean we can achieve run-time polymorphism without allocation/deallocation ? if yes, how ?
[2] We can use a base class as the interface of a scoped object of a derived class
==> What is a scoped object ? Maybe a code example of 'scoped' and a 'non-scoped' object be really helpful.
[3] 'This' is done where dynamic allocation is prohibited (e.g. hard-real-time) and to provide a stable interface to some kinds of plug-ins
==> What is "This" here?
==> How is "This" achieved without dynamic allocation ? Would really appreciate a code example.
Thanks alot for any help :)