如果您编写以下程序:
template <typename T>
struct A{
A(T& xx):x{xx} {}
template <int n>
void f() {cout << n << '\n';}
T& x;
};
int main(){
int x = 5;
A{x}.f<3>();
}
它在g ++ 7.3(-std = c ++ 17)中可以很好地编译,但是在clang-6.0中给出错误“ expected unqualified-id”。
但是,如果您不是
A{x}.f<3>();
写
::A{x}.f<3>();
它在两个编译器中均可完美编译。为什么?