I am not really getting any smarter from these error messages.
Minimal (not) Working Example on godbolt
#include <initializer_list>
#include <memory>
#include <vector>
struct S
{
int j;
double y;
std::vector<int> data;
S(int i, double x, std::initializer_list<int> list)
: j(i)
, y(x)
, data(list)
{
}
};
int main()
{
auto ptr = std::make_shared<S>(1, 1.2, {1,2,3}); // I want this to work
// auto ptr = std::make_shared<S>(1, 1.2, std::initializer_list<int>({1,2,3})); // works
}
Errors:
<source>:22:35: error: too many arguments to function 'std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = S; _Args = {}]'
22 | auto ptr = std::make_shared<S>(1, 1.2, {1,2,3});
<source>:11:5: note: candidate: 'S::S(int, double, std::initializer_list<int>)'
11 | S(int i, double x, std::initializer_list<int> list)
| ^
<source>:11:5: note: candidate expects 3 arguments, 0 provided
It compiles fine, when I call the explicit constructor for std::initializer_list<int>
in front of {1,2,3}
. Is there a way to circumvent this, so my std::make_shared
does not bloat so much?