Q: How can I use std::unique_ptr as a static map of a class I have a base class for all entities of my application, which makes use of a map of smart pointers:
class CEntityBase
{
 CEntityBase()
 {
    m_nID = m_nNextValidID;
    m_entityMap.insert(std::make_pair(m_nID, std::make_unique<CEntityBase>()));
    m_nNextValidID++;
 }
~CEntityBase() { m_EntityMap.erase(m_nID); }
 ....
 private:
  int m_nID;
  static int m_nNextValidID;

 protected:
   static std::map<int, std::unique_ptr<CEntityBase> m_entityMap;
}

int CEntityBase::m_nNextValidID = 0;

Every time a new instance of the class is created, its constructor creates a new pair inside the map, in order to keep track of the IDs of every instance.
But if an instance does not exist then the app falls to an endless recursion since the destructor of the class have to remove the pair from the map.
Is there any way to handle this situation without use of another class that will serve as a manager of the CEntityBase class?
