7
嘗試針對該類的特定構造函數的特定類類型嘗試別名make_shared。我最好的嘗試:Constexpr重載模板函數的別名
class foo { public: foo(int x) : y(x) {} int y; };
constexpr auto newfoo = static_cast<std::shared_ptr<foo>(*)(int)>(std::make_shared<foo>);
產量:
error: invalid static_cast from type ‘<unresolved overloaded function type>’ to type ‘std::shared_ptr<foo> (*)(int)’
constexpr auto newfoo = static_cast<std::shared_ptr<foo>(*)(int)>(std::make_shared<foo>);
我在做什麼錯?
+1,但是你應該在你的「如果你真的想要」例子中使用'const int&'而不是'int &&'。就像,'const int i = 42; auto f = newfoo(i);'不起作用。 –
@MilesBudnek:好點,改變我的回答 –
'constexpr auto newfoo = std :: make_shared'只是工作。爲什麼我們需要演員? –
Zefick