If I explicitly specify the template argument <T>
after the constructor, it builds fine with C++17 but fails with C++20 (verified with OnlineGDB).
template <class T>
struct Foo {
Foo<T>() = default;
};
int main() {
Foo<int> foo;
return 0;
}
With C++20, the compiler will throw the error
main.cpp:3:16: error: expected unqualified-id before ‘)’ token
3 | Foo<T>() = default;
| ^
To build with C++20, I must remove <T>
, e.g.
template <class T>
struct Foo {
Foo() = default;
};
int main() {
Foo<int> foo;
return 0;
}
Why?