This code works, without having to specify a constructor:
struct Foo
{
int a;
int b;
};
//...
int a1, b1;
Foo foo = {a1, b1};
If I make Foo a template, it doesn't work.
template<typename T1, typename T2>
struct Foo
{
T1 a;
T2 b;
};
//...
int a1, b1;
Foo foo = {a1, b1};
It says deduction failed / 2 arguments were provided while 1 expected. If I add a constructor like Foo(T1, T2){}
then it works. I thought, that sort of construction just works by default for structs. What am I getting wrong?
EDIT: I'm using Clang, which seems not to support it. Both MSVC and GCC compile it with c++20 compiler flag.
Foo<Int, int> foo = {a1, b1};
. godbolt.org/z/Eqcc7Pefn – HomopterousFoo foo = {{a1, b1}};
. – Meprobamate