I have the following exercise:
Add code to make it run properly.
class MyInt
{
public:
private:
int* MyValue;
}
int main(int argc,char** argv)
{
MyInt x(1);
...//a bit more code where the actual value of x is going to be used.
return 0;
}
I added as a private property
int val;
and a public constructor
Myint(int x)
{
val = x;
MyValue = &val;
}
I added the int val as a way for the constructor to assign to MyVal an address of an object that is not temporary, as the x.
Is there a neat(er) way to answer this exercise?