vendredi 30 avril 2021

Where is the memory location of list of objects (list

class InnerObj{
// implementation
};

class OuterObj{
public:
   void innerObjFactory() { my_innerObjs.pushback( ########## <Q2> ########## )}; // line Q2

private:
   list<InnerObj> my_innerObjs;
};

int main(int argc, char *argv[])
{
 ########## <Q1> ##########; // line Q1
}

So my question is considering the 4 combinations:

line Q1 line Q2
created in the stack (ex: OuterObj aa;) created in the stack (ex: InnerObj(); )
created in the stack (ex: OuterObj aa;) created in the free store/heap (ex: new InnerObj(); )
created in the free store/heap (ex: OuterObj *aa = new OuterObj();) created in the stack (ex: InnerObj(); )
created in the free store/heap (ex: OuterObj *aa = new OuterObj();) created in the free store/heap new InnerObj();

Where in memory (free store or stack) is the objects at line Q2 are created?

Aucun commentaire:

Enregistrer un commentaire