Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions