Denis Steinman
Denis Steinman

Reputation: 7799

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.

Upvotes: 1

Views: 84

Answers (1)

Vittorio Romeo
Vittorio Romeo

Reputation: 93274

Your m_impl is a pointer to an unique_ptr.

Change

std::unique_ptr<Impl> *m_impl;

to

std::unique_ptr<Impl> m_impl;

Upvotes: 4

Related Questions