Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started