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.
2 Answers
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 ?
Hot today
Python — File Handling
0 Votes
Help me solve this (using loop)
3 Votes
What is wrong? Error on test.
1 Votes
Help me wiht python
1 Votes
Question is write a c program to print prime numbers up to n and print the largest number in array.
1 Votes
Help me
0 Votes