Question: public: MyInt(int val){ m_data = new int(val); } ~MyInt() { cout < < deleting: < < *m_data < < endl; delete m_data; } //
public: MyInt(int val){ m_data = new int(val); } ~MyInt() { cout << "deleting: " << *m_data << endl; delete m_data; } // create a copy constructor for this dynamic class <-------------------------------------
// Copy constructor goes here {
}
void get(MyInt mi) { cout << "Getting MyInt!" << endl; }
int main() { MyInt I(200); get(I); return 0; }
/* output: Getting MyInt! deleting: 200 deleting: 200
*/ How do i create a copy constructor for this dynamic class , no code can be changed just have to add the copy constructor
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
