Шах Шах - 3 months ago 7
C++ Question

Cannot make pimpl

I try to make pimpl pattern:

//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>() }
{

}


But I get an error:


table.cpp:9: error: cannot convert 'brace-enclosed initializer list' to 'std::unique_ptr*' in initialization : m_impl { std::make_unique() }


I can't understand that I do wrong and how to fix it.

Answer

Your m_impl is a pointer to an unique_ptr.

Change

std::unique_ptr<Impl> *m_impl;

to

std::unique_ptr<Impl> m_impl;
Comments