2016-08-18 78 views
0

我尽量让PIMPL模式:不能使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: error: cannot convert 'brace-enclosed initializer list' to 'std::unique_ptr*' in initialization : m_impl { std::make_unique() }

我不明白,我做错了,如何解决它。

回答

4

您的m_impl是指向unique_ptr的指针。

变化

std::unique_ptr<Impl> *m_impl; 

std::unique_ptr<Impl> m_impl; 
+0

谢谢!这是一个愚蠢的错误,只是我只学习C++。 –