I have the following exercise:
Add code to make it run properly.
class MyInt
{
public:
private:
int* MyValue;
}
int main(int argc,char** a
I don't see anything in your original problem statement that requires the pointer to be initialized to the address of an int. The minimal code required to fix the example would be to add a constructor that takes an int, and initialize MyValue to nullptr.
class MyInt
{
public:
MyInt(int) {}
private:
int* MyValue = nullptr;
};
int main(int argc,char** argv)
{
MyInt x(1);
return 0;
}
If your compiler doesn't support C++11 then
class MyInt
{
public:
MyInt(int) : MyValue(NULL) {}
private:
int* MyValue;
};