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