C++ 模板函数的两种特殊化(int和int*)。编译错误

C++ 模板函数的两种特殊化(int和int*)。编译错误,c++,templates,template-specialization,C++,Templates,Template Specialization,编译器Visual C++ 2010 你尝试使用地址作为模板参数。如果您试图用gcc或clang编译代码,您会得到,在gcc中 Error 1 error C2440: "specialization" : cannot convert from "int *" to "const int" line 11 Error 2 error C2973: invalid template argument "int *" line 11 Error 3 error C2440

编译器Visual C++ 2010

你尝试使用地址作为模板参数。如果您试图用gcc或clang编译代码,您会得到,在gcc中

Error   1   error C2440: "specialization" : cannot convert from "int *" to "const int" line 11
Error   2   error C2973: invalid template argument "int *" line 11
Error   3   error C2440: "specialization" : cannot convert from "int *" to "const int" line 11
Error   4   error C2973: invalid template argument "int *" line 11
Error   5   error C2668: 'f' : ambiguous call to overloaded function line 11
叮当作响:

test.cpp:11:13: error: a cast to a type other than an integral or enumeration type cannot     appear in a constant-expression
test.cpp:11:21: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
根据这个答案,哪一个是正确的:


也就是说,尽管接受指针,但它们应该仅是指向具有外部链接的命名对象的指针

您正在尝试使用地址作为模板参数。如果您试图用gcc或clang编译代码,您会得到,在gcc中

Error   1   error C2440: "specialization" : cannot convert from "int *" to "const int" line 11
Error   2   error C2973: invalid template argument "int *" line 11
Error   3   error C2440: "specialization" : cannot convert from "int *" to "const int" line 11
Error   4   error C2973: invalid template argument "int *" line 11
Error   5   error C2668: 'f' : ambiguous call to overloaded function line 11
叮当作响:

test.cpp:11:13: error: a cast to a type other than an integral or enumeration type cannot     appear in a constant-expression
test.cpp:11:21: error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
根据这个答案,哪一个是正确的:

也就是说,尽管接受指针,但它们应该仅是指向具有外部链接的命名对象的指针

好的,你会有错误,但是什么错误呢?请编辑您的问题以显示实际的错误。好的,您得到了错误,但是什么错误?请编辑您的问题以显示实际错误。