S
swh
Hello.I'm start to write some templates,but I have some questions about
them.
#include <iostream>
using namespace std;
template<typename T> void f(T const& a) {
cout << "Primary" << endl;
}
void f(int const& a) {
cout << "Non-template" << endl;
}
template<> void f(int const& a) {
cout << "Full" << endl;
}
int main() {
f(1.0); // line 1
f(1); // line 2
f<>(1); // line 3
}
The result is:
Primary
Non-template
Non-template
I don't understand the third line in main().I have specified the angle
brackets after the f,
but the resulting call is the Non-template version.Why?
them.
#include <iostream>
using namespace std;
template<typename T> void f(T const& a) {
cout << "Primary" << endl;
}
void f(int const& a) {
cout << "Non-template" << endl;
}
template<> void f(int const& a) {
cout << "Full" << endl;
}
int main() {
f(1.0); // line 1
f(1); // line 2
f<>(1); // line 3
}
The result is:
Primary
Non-template
Non-template
I don't understand the third line in main().I have specified the angle
brackets after the f,
but the resulting call is the Non-template version.Why?