Compile & run the code to see the crash. Use valgrind to show memory leak(or som
ID: 3565402 • Letter: C
Question
Compile & run the code to see the crash. Use valgrind to show memory leak(or something else). Add copy constructor and = operator for both First and Second classes - compile, rerun the program & check with valgrind to make sure that all the problems are resolved.
#include <iostream>
using namespace std;
class First
{
private:
int *aptr;
int size;
public:
First(int s = 5) {
size = s;
aptr = new int [s];
}
~First() {
delete [] aptr;
}
};
class Second
{
private:
First *bptr;
int size;
public:
Second(int s=3) {
size = s;
bptr = new First [s];
}
~Second() {
delete [] bptr;
}
};
int main()
{
Second x;
Second y(x);
Second z;
z = x;
}
Explanation / Answer
umm too late.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.