I'm having trouble with some code, where I need to pass a pointer through multiple layers of functions. The pointer can be null so I've an overload for the final function for the case of nullptr. Conceptual I've something like this:
void test_ptr(std::nullptr_t)
{
std::cout << "nullptr" << std::endl;
}
void test_ptr(double *d)
{
std::cout << *d << std::endl;
}
void test(double *d)
{
test_ptr(d);
}
int main()
{
test(nullptr);
}
For me, the ideal behaviour would be, if test
calls the first version of test_ptr
, but this isn't the case. Is there any chance to manipulate test
so that it calls the "right" version?