【问题标题】:Cannot make pimpl不能制造粉刺
【发布时间】:2016-08-18 10:45:36
【问题描述】:

我尝试制作 pimpl 模式:

//header
#include <memory>

class Table
{
public:
    Table();

private:
    class Impl;
    std::unique_ptr<Impl> *m_impl;
};
//source
#include <vector>
#include "table.hpp"

struct Table::Impl {
    Impl();
};

Table::Table()
    : m_impl { std::make_unique<Impl>() }
{

}

但我得到一个错误:

table.cpp:9:错误:在初始化中无法将“大括号括起来的初始化列表”转换为“std::unique_ptr*”:m_impl { std::make_unique() }

我不明白我做错了什么以及如何解决它。

【问题讨论】:

    标签: c++ c++14 pimpl-idiom


    【解决方案1】:

    您的m_impl 是指向unique_ptr 的指针。

    改变

    std::unique_ptr<Impl> *m_impl;
    

    std::unique_ptr<Impl> m_impl;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-05
      • 2012-09-14
      • 2023-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多