I have some type deduction guide issue with a simple class template, that is instantiated issues in the main function scope, but fails to do that inside another class.
Here is an example:
template<class T>
struct X
{
X(T&)
{
}
};
struct User
{
X x{1}; // error: invalid use of template-name 'X' without an argument list
};
int main()
{
int i;
auto x = X(i); // OK
(void)x;
}
I am kind of puzzled, why is that and how this can be fixed. Any ideas?
Clangd gives a more meaningful error message, which would have probably made easier for you (or me, or anyone else) to search the web for an answer,
Use of class template 'X' requires template arguments;
argument deduction not allowed in non-static struct member
and the reason for this is well explained here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With