2016-08-18 77 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++。 –