考虑以下代码:
\n\nstruct Test {\n template <int S>\n bool call();\n};\n\ntemplate <>\nbool Test::call<0>() {\n return false;\n}\n\ntemplate <>\nbool Test::call<1>() {\n return true;\n}\n\ntemplate <int S, typename T>\nstatic void func(T& t) {\n t.call<S>();\n}\n\nint main()\n{\n Test t;\n func<0>(t);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我遇到编译错误:
\n\na.cpp: In function \xe2\x80\x98void func(T&)\xe2\x80\x99:\na.cpp:19:15: error: expected primary-expression before \xe2\x80\x98)\xe2\x80\x99 token\na.cpp: In instantiation of \xe2\x80\x98void func(T&) [with int S = 0; T = Test]\xe2\x80\x99:\na.cpp:25:14: required from here\na.cpp:19:5: error: invalid operands of types \xe2\x80\x98<unresolved overloaded function type>\xe2\x80\x99 and \xe2\x80\x98int\xe2\x80\x99 to binary \xe2\x80\x98operator<\xe2\x80\x99\nRun Code Online (Sandbox Code Playgroud)\n\n如果我把t.call<0>() …