I notice that if I write:
template<typename T = int> void Test(T t) {};
then the following code does not compile:
auto x = Test;
However, this code does, and deduces x to be void (*x)(int t):
auto x = Test<int>;
I'm just wondering why it does not just assume the type parameter is int in the first case and treat it the same as the second one?
If you have a function with a default parameter, for example:
int f(int n=0);
Calling this function with this parameter defaulted is done by doing this:
int g=f();
and not this:
int g=f;
Same principle applies to template instantiations:
auto x = Test<>;
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