I have been researching into RAII (http://tomdalling.com/blog/software-design/resource-acquisition-is-initialisation-raii-explained/) and have a number of questions!
There are some strong arguments for initialising objects on the stack. Is there ever a good scenario to allocate memory on the heap?
How does this work with polymorphic objects? For example, you have an abstract base class called
Biome
and you need a container of biomes. This container needs to store objects ofOcean
,Tundra
,Desert
etc. Are there any issues or strong arguments against allocating these objects on the stack, but then storing pointers to these objects in a container of pointer to Biome? I am aware that once the encapsulating objects go out of scope, these objects will be destroyed and their pointers will be addressed to memory which potentially does not exist.