You are returning Complex
, which is not a pointer. In order to return nullptr
, your return type should be Complex*
.
Noticed your edit - here's what you can do:
bool Complex::sqrt(const Complex& cmplx, Complex& out) {
if(cmplx._imag == 0)
{
// out won't be set here!
return false;
}
out = Complex(...); // set your out parameter here
return true;
}
Call it like this:
Complex resultOfSqrt;
if(sqrt(..., resultOfSqrt))
{
// resultOfSqrt is guaranteed to be set here
}
else
{
// resultOfSqrt wasn't set
}