I have these files :-
1.h :-
#include <iostream>
using namespace std;
template <typename A>
void f() {
cout<<"generic\n";
}
1.cpp :-
#include "1.h"
template <>
void f<int> () {
cout<<"for ints only\n";
}
main.cpp:
#include "1.h"
int main() {
f<int>();
return 0;
}
现在,我使用g++编译和运行这些代码,方法如下:-
g++ -c 1.cpp -o 1.o
g++ main.cpp 1.o
./a.out
And I get :-
for ints only
另一方面,我使用icpc编译它,如下所示:-
icpc -c 1.cpp -o 1.o
icpc main.cpp 1.o
./a.out
And I get :-
generic
C++标准对此有何规定?是否有任何一个编译器是“正确”的,而另一个是“错误”的?或者标准在这个问题上存在歧义,两者都是“正确”的?