I have this class widget:
class widget_11 {
public:
template<typename T>
void process_pointer(T* ptr)
{
std::cout << *ptr;
}
};
my issue is that I don't understand whats the difference between these two declarations:
template<>
void widget_11::process_pointer(double*) = delete;
template<>
void widget_11::process_pointer<double>(double*) = delete;
My question is if these two definitions of deleted functions do the same thing? From my testing they both compile and didn't change how code works, but maybe I skipped something important while testing
CodePudding user response:
Both of those are declarations and definitions for an explicit specialization of process_pointer
for T = double
so they would define the same thing the same way.
When you write out the declaration for an explicit specialization, template argument deduction can be used to fill in types not specified. In the case of your first declaration, T
is deduced as double
from T* = double*
. In the case of your second declaration, T
is explicitly specified as double
, and no template argument deduction is done.
There is also a third equivalent declaration:
template<>
void widget_11::process_pointer<>(double*) = delete;
// T needs to be deduced here ^^
And these empty angle brackets can just be omitted, leading to your first declaration.