given the following C++ code:
class XY
{
public:
int p;
XY(int i):p{i}
{}
XY& operator=(const XY& cs)
{
if (==nullptr) //????
{
p=0;
return *this;
}
...
return *this;
}
};
int main ()
{
XY a=3;
XY *s=nullptr;
a=*s;
}
a is type of XY and s is a pointer of this class that points to null. How can I program the assignment-operator so that if s is a null pointer, that a.p=0?