Код: Выделить всё
/* testing data section begin */
class CHuge
{
public:
void DoAction(){}
};
constexpr bool g_bSomeCondition1 = true;
constexpr bool g_bSomeCondition2 = true;
constexpr bool g_bSomeCondition3 = true;
/* testing data section end */
class CWorker
{
public:
CWorker() : m_pHuge(nullptr)
{ }
CWorker(const CWorker& rhs) : m_pHuge(nullptr)
{
if (rhs.m_pHuge)
{
m_pHuge = new CHuge(*rhs.m_pHuge);
}
}
CWorker(CWorker&& rhs) : m_pHuge(rhs.m_pHuge)
{
rhs.m_pHuge = nullptr;
}
CWorker& operator=(const CWorker& rhs)
{
if (this != &rhs)
{
if (m_pHuge)
{
delete m_pHuge;
m_pHuge = nullptr;
}
if (rhs.m_pHuge)
{
m_pHuge = new CHuge(*rhs.m_pHuge);
}
}
return *this;
}
~CWorker()
{
delete m_pHuge;
}
void Process()
{
if (!m_pHuge)
{
m_pHuge = new CHuge;
}
m_pHuge->DoAction();
}
private:
CHuge* m_pHuge;
};
int main()
{
CWorker worker1;
if (g_bSomeCondition1)
{
worker1.Process();
}
CWorker worker2;
if (g_bSomeCondition2)
{
worker2 = worker1;
}
if (g_bSomeCondition3)
{
worker1.Process();
worker2.Process();
}
return 0;
}