I have already object of CCompositePrimitive class in Main.cpp
int main()
{
...
CCompositePrimitive DrawObjects;
...
}
The CCompositePrimitive class has field:
private:
list<CDrawObject*> m_Objects;
and method:
public:
Add(...);
void CCompositePrimitive::Add() {
Objects.push_back(new Rectangle(...))
}
On some forums ask me that DrawObjects object will be stored in heap. But I think else. In my opinion DrawObjects object will be stored in stack.
How I can preserve computer’s memory of stack overflow (any different memory problems), if DrawObjects can store in list m_Objects; very many objects, which can content CCompositePrimitive objects too (composite pattern).
Depends on how the class where
CCompositePrimitive m_DrawOjects;is stored in gets created. (I assume it’s stored inside a class because of them_)If your class is created on the stack, then
m_DrawObjectswill be too. If your class is created on the heap, so will bem_DrawObjects.But indifferent of wether
m_DrawObjectsis created on the heap or the stack, the objects inside thelist<CDrawObject*> m_Objects;will be created on the heap, because that’s how a linked list works.Edit: According to your edit and comment, then
DrawObjectsis of course created on the stack. 🙂 But what I said about the objects inside the list still holds true.