Question: Answer in C++ Consider the following class definition: class ClassX { private: int * ptr; public: ClassX(int val = 0) { ptr = new int;

Answer in C++ Consider the following class definition:

class ClassX {

private:

int * ptr;

public:

ClassX(int val = 0) {

ptr = new int;

*ptr = val;

}

ClassX (const ClassX $ obj) {

ptr = new int;

*ptr = *(obj.ptr):

}

void setVal(int val) {

*ptr = val;

}

int getVal() {

return *ptr;

}

};

What would be displayed by executing the following client code?

ClassX obj1(22);

ClassX obj2 = obj1;

obj2.setVal(375);

cout << obj1.getVal() <<" "<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!