c++ - make_unique 给出错误 2248

标签 c++ visual-c++ unique-ptr c++14

我遇到了 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

我找不到任何关于 SO 上处理 make_unique 或 unique_ptr 的错误。否则我不会问这个。

一如既往地感谢您的宝贵时间和建议。

最佳答案

你可能想写

std::make_unique<FlInput>(80, 10, 210, 25, "Find:")

代替

std::make_unique<FlInput>(FlInput{80, 10, 210, 25, "Find:"})

FlInput 类似乎有一个私有(private)拷贝和/或移动构造函数,使第二种形式非法。

关于c++ - make_unique 给出错误 2248,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26579178/

相关文章:

c++ - std::unique_ptr ABI 与原始指针兼容吗?

c++ - 使用Boost Bind与std::Transform

c++ - 在从模板化基类派生的类中使用虚方法

c - 调试断言失败! VS 升级后堆指针无效

c++ - 虚函数实现缺少类型说明符

c++ - 如何用元组转发unique_ptr?

c++ - 在 unique_ptr vector 中搜索时出现非标准扩展警告

c++ - msvcrt.dll 是否为其 rand() 函数使用线性同余生成器?

c++ - 继承的纯虚函数

winapi - 以编程方式修改/检测本地安全策略