#include <iostream>
using namespace std;
template<typename T> void test()
{
cout << "Called from template T";
}
template<int I> void test()
{
cout << "Called from int";
}
int main()
{
test<int()>();
}
In the above snippet test<int()>()
calls the first version and gives output
Called from template T
Why doesn't the second version get called?
As per ISO C++03 (Section 14.3/2
)
In a template-argument, an ambiguity between a type-id
and an expression is resolved to a type-id
. int()
is a type-id
so the first version gets called.
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