我和make_unique有个问题,我对此很茫然。
_replace_find = unique_ptr<Fl_Input>(new Fl_Input{ 80, 10, 210, 25, "Find:" });
_replace_find = make_unique<Fl_Input>(Fl_Input{ 80, 10, 210, 25, "Find:" });当我使用make_unique行时,它会给出这个错误,但是当我使用另一个行时,它会编译得很好。根据我的理解,make_unique几乎做了同样的事情,但异常安全。
Error 1 error C2248: 'Fl_Widget::Fl_Widget' : cannot access private member declared in class 'Fl_Widget' c:\program files (x86)\microsoft visual studio 12.0\vc\include\fl\fl_input_.h 488 1 hayley在处理make_unique或unique_ptr时,我找不到任何与此相关的错误。否则我就不会问这个了。
一如既往地感谢你的时间和建议。
发布于 2014-10-26 23:35:04
你可能想写
std::make_unique<FlInput>(80, 10, 210, 25, "Find:")而不是
std::make_unique<FlInput>(FlInput{80, 10, 210, 25, "Find:"})类FlInput似乎有一个私有副本和/或移动构造函数,使第二种形式成为非法。
发布于 2014-10-26 23:37:35
_replace_find = unique_ptr<Fl_Input>(new Fl_Input{ 80, 10, 210, 25, "Find:" });
_replace_find = make_unique<Fl_Input>(Fl_Input{ 80, 10, 210, 25, "Find:" });这些线条不是等价的。
第一行在空闲存储上创建一个Fl_input,然后用它初始化一个unique_ptr。
第二个创建临时Fl_input并使用它调用make_unique<Fl_input>,它通过调用复制/移动ctor在空闲存储上创建一个新实例(显然这是不可访问的,因此出现了错误)。
您想要的是将所有的ctor-参数提供给make_unique<Fl_input>。
_replace_find = make_unique<Fl_Input>(80, 10, 210, 25, "Find:");https://stackoverflow.com/questions/26579178
复制相似问题