samedi 27 juillet 2019

When to have class member on heap vs stack?

I am learning C++ OO design. When to declare class member on heap vs stack?

class RacingLiveEvent
{
public:
    playerlist  *pl;
}

vs

class RacingLiveEvent
{
public:
    playerlist  pl;
}

What design/runtime/compiletime considerations will help me decide. Any suggestions please?

I see with heap, I can define each class in its own header file. If I use static object, I need all the dependent class to be in one file.

Aucun commentaire:

Enregistrer un commentaire