Can anyone make it clear for me why I can call std::make_unique<S>
with only one template parameter, i.e. S
, like this:
auto p = std::make_unique<S>(12, 13);
But, I cannot pass std::make_unique<S>
to a function to do that for me, like this:
template <typename FuncType, typename ...Args >
void call_method(FuncType f, Args... args)
{
f(std::forward<Args>(args)...);
}
struct S
{
S(int x, int y) {}
};
int main()
{
call_method(std::make_unique<S>, 12, 13); // not working
// call_method(std::make_unique<S, int , int>, 12, 13); // works fine
return 0;
}
The shown error by the compiler is:
Error C2512 'S::S': no appropriate default constructor available.
I am working with Visual Studio 2017 on Windows 10.
Aucun commentaire:
Enregistrer un commentaire