Considering the function :
template <class T> void f(const T* const ptr);
What is T
for f(nullptr)
?
Type inference or deduction refers to the automatic detection of the data type of an expression in a programming language. It is a feature present in some strongly statically typed languages. In C++, the auto keyword(added in C++ 11) is used for automatic type deduction.
The nullptr keyword can be used to test if a pointer or handle reference is null before the reference is used. Function calls among languages that use null pointer values for error checking should be interpreted correctly. You cannot initialize a handle to zero; only nullptr can be used.
I would have to answer this with there is none. From § 2.14.7/1 (emphasis mine):
The pointer literal is the keyword nullptr. It is a prvalue of type std::nullptr_t. [Note: std::nullptr_t is a distinct type that is neither a pointer type nor a pointer to member type; rather, a prvalue of this type is a null pointer constant and can be converted to a null pointer value or null member pointer value.
T *
would have to be std::nullptr_t
and since std::nullptr_t
is not a pointer type, that isn't possible. Trying to call it with nullptr
on GCC 4.7.2 gives an error indicating that it was trying to call f(std::nullptr_t)
, but only had f(const T *)
, which agrees with the fact that a std::nullptr_t
is not a T *
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With