Constructor delegation from body of constructor | Sololearn: Learn to code for FREE!

0

Constructor delegation from body of constructor

Not sure why but seems some issue to save the new code from playground on windows 10, so pasting code into query itself: class myString { public: myString() : m_pCharName(nullptr), m_intSize(0) { cout << "null contructor called\n"; } ~myString() { cout << "Destructor called\n"; if (m_pCharName) delete[] m_pCharName; } myString(const char* pInput) { if (pInput == nullptr) myString(); else { m_intSize = strlen(pInput); m_pCharName = new char[m_intSize + 1]; strcpy_s(m_pCharName, m_intSize + 1, pInput); } } private: char* m_pCharName; int m_intSize; }; Question is on constructor delegation. Is below line proper? if (pInput == nullptr) myString(); I want to call non parametric constructor in case of input as nullptr.

5/3/2022 11:22:35 AM

Ketan Lalcheta

2 Answers

New Answer

0

Let me write in different words : Why code below observes memory issue ? https://code.sololearn.com/cYBe2NnYd4Ek/?ref=app

0

Hi community , Any solution on this , plz ?