Question: A program contains the following code. Line numbers have been added to make it easier for you to refer to them in your answer, but
A program contains the following code. Line numbers have been added to make it
easier for you to refer to them in your answer, but they are not part of the program.
class MyClass
public:
MyClassint int;
void execvoid;
private:
int i;
int ip;
;
MyClass::MyClassint a int b
thisi a;
thisip b;
int MyClass::execvoid
ip i;
a What does an object of MyClass do
b Write out the type of MyClasss constructor in english words.
c Rewrite the constructor so that it uses an initialisation list instead of explicit
assignment.
d A programmer writes the following code which compiles without error:
int v ;
MyClass c v;
cexec;
When the program runs, it produces a segmentation fault. Explain what the
programmer has done wrong.
e The code is to be converted to use a std::uniqueptr object instead of a
primitive pointer. Write down the declaration of v using such a pointer.
f What changes would have to be made to MyClass to allow it to operate with
a unique pointer instead of a primitive pointer?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
