MISRA Discussion Forums

Full Version: Rule 18-4-1 (ban of dynamic heap memory allocation)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
One of the most commonly quoted advantages of object orientation is polymorphism.
C++ often relies on dynamically allocated pointers to achieve (run-time) polymorphism.

How can polymorphism be achieved without resorting to dynamic memory allocation?
I suspect that preallocating pointers on the stack is the answer but can someone please write some example code?

Thanks.
Polymorphism and the use of dynamic memory are not intrinsically linked, so polymorphism is possible without the use of dynamic memory