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
Get step-by-step solutions from verified subject matter experts
